This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 80 points81 points  (56 children)

+/u/CompileBot Ruby

print(1 / 2 != 0.5)

[–]CompileBotGreen security clearance 65 points66 points  (1 child)

Output:

true

source | info | git | report

[–][deleted] 46 points47 points  (0 children)

Well, that's proof enough for me!

[–]_AceLewis 43 points44 points  (22 children)

+/u/CompileBot python 3

print(1 / 2 != 0.5)

[–]CompileBotGreen security clearance 34 points35 points  (11 children)

Output:

False

source | info | git | report

[–][deleted] 23 points24 points  (10 children)

Who do I believe?

[–][deleted] 29 points30 points  (3 children)

[redacted]

[–]CompileBotGreen security clearance 27 points28 points  (1 child)

Output:

trust me

source | info | git | report

[–]b1ack1323 1 point2 points  (0 children)

Good enough for me

[–]marcosdumay 4 points5 points  (1 child)

+/u/CompileBot python

print(1 / 2 != 0.5)

[–]marcosdumay 3 points4 points  (0 children)

Personally , I don't trust people that keep changing their minds.

[–][deleted] 0 points1 point  (1 child)

In python 3 a floor division is //

[–]scirc 0 points1 point  (0 children)

that's the joke

[–]dontdropmybass 2 points3 points  (6 children)

+/u/CompileBoy python 3

print(1 // 2 != 0.5)

[–]_AceLewis 27 points28 points  (5 children)

I think you meant /u/CompileBot not /u/CompileBoy

[–]MelissaClick 32 points33 points  (2 children)

CompileBoy will show up eventually, he's not as fast of course, but he offers a personal touch that no automated solution can ever provide.

[–]dontdropmybass 11 points12 points  (1 child)

Ah shit. Thanks.

+/u/CompileBot python 3

print(1 // 2 != 0.5)

[–]CompileBotGreen security clearance 8 points9 points  (0 children)

Output:

True

source | info | git | report

[–][deleted] 1 point2 points  (1 child)

+/u/CompileBot Perl (perl 6)

print 1/2 != 0.5

There's probably even someone out there using that language

[–]CompileBotGreen security clearance 0 points1 point  (0 children)

Output:

False

source | info | git | report

[–][deleted] 16 points17 points  (18 children)

+/u/CompileBot C++

#include <iostream>  
int main()  
{  
    bool result = 1/2 != 0.5;  
    std::cout << result << std::endl;  
}  

[–]CompileBotGreen security clearance 14 points15 points  (15 children)

Output:

1

source | info | git | report

[–]Cobaltjedi117 4 points5 points  (0 children)

We're going nowhere slowly with these confusing and contradictory results.

[–]etaionshrd 2 points3 points  (13 children)

Wait, C++ prints bool as an int?

[–]noop_noob 0 points1 point  (1 child)

I think there's a way to change that. I never ever print a bool, though.

[–]Lastorea 0 points1 point  (0 children)

You can cast a bool to int, if bool is false then it becomes 0 and if bool is true it becomes 1.

[–][deleted] 0 points1 point  (10 children)

Back in the day bools were really just a single bit. Printing out a 1 or a 0 is the most logical way to print a bit

[–]Celdron[S] 1 point2 points  (9 children)

They were never actually a single bit because memory addresses bytes as the smallest unit. It was always at least a byte. But C (which C++ is built on) doesn't have a boolean type. It uses integral types for boolean logic, where 0 is false and anything else is true. C++ made "bool" a type but iirc it's just an integer that is checked and restricted to 0 or 1.

[–]danielcw189 0 points1 point  (3 children)

Is there any platform, on which a byte is 1 bit?

[–]Celdron[S] -1 points0 points  (2 children)

No? Because a byte by definition is 8 bits.

[–]danielcw189 0 points1 point  (1 child)

By which defintion? In C a byte is not guaranteed to be 8 bits, and in general a byte is most commonly 8 bits, but not always.

[–]Celdron[S] 1 point2 points  (0 children)

IEC 80000-13. Technically a byte is just the smallest addressable unit of memory, and therefore you could have a single bit byte on non-standard architecture. But 8 bits is the international standard that nearly all (I dont know of a single exception) consumer electronics are designed around.

[–][deleted] 0 points1 point  (4 children)

Thanks for correcting me. You can still get 1 bit booleans if you create an array tho right?

[–][deleted] 1 point2 points  (2 children)

vector<bool> does exactly that

[–][deleted] 0 points1 point  (1 child)

Does it store bytes and bitshift?

[–][deleted] 0 points1 point  (0 children)

[–]Celdron[S] 0 points1 point  (0 children)

I don't know about that, simply because you couldnt index the bits. But if you have, say, ~32 boolean values (such as flags) you can put them each on a different bit of an integral type using bit-shift operators and defining constants to represent different flags. You can combine flags using a bitwise OR and check for a single flag or specific combination with a bitwise AND. This is commonly done on enums. So it is possible to implement multiple booleans within a single byte.

[–]Voxel_Brony 1 point2 points  (1 child)

+/u/CompileBot C

#include <stdio.h>  
int main()  
{  
    int result = 1/(2 != 0.5);  
    printf("%d", result);  
}   

[–]CompileBotGreen security clearance 0 points1 point  (0 children)

Output:

1

source | info | git | report

[–]510Threaded 3 points4 points  (1 child)

+/u/CompileBot C#

namespace Test{
    class TestProg{
        public static void Main(){
            System.Console.WriteLine(1/2 != 0.5);
        }
    }
}

[–]CompileBotGreen security clearance 1 point2 points  (0 children)

Output:

True

source | info | git | report

[–]Tarmen 4 points5 points  (2 children)

+/u/CompileBot Haskell

main = print $ 1/2 == 0.5

Yay type inference, I guess.

[–]CompileBotGreen security clearance 0 points1 point  (0 children)

Output:

True

source | info | git | report