Unexpected fun (or fun facts)
-
Yes, guys, you nailed it. 😄😆
-
How do mathematicians deal with constipation?
They sit down and work it out with a pencil.
-
what is a computers favorite food?... bits and chips
-
Depending on your integer size 4294967297 + 4294967297 = 2 ;-) also you can get over it if you use int() to define your integer value.
(further down in the code you need aupdate()
andsleep(10)
, not shown in the screenshot)
We seem to have 4 bytes available if we use a normal int assignment (not over the int() return value).
FFFF FFFF = 0 = 4294967296 = 2^32
Maybe int() returns a 64 bit integer? -
Yes, Fuze integers are 64 bit signed values, but the constant literals (numbers typed into the code editor) are 32 bit signed values. It is somewhat unusual for literals to be a smaller type than the variables they are assigned to. It makes for some interesting code if you want to use larger integers.
-
...so if you do ’x = 4294967296
y = x+x
Print(y)’You’ll get the right answer?
-
@toxibunny well not wrong, but probably not what you would expect. The number is stored in x as 0. So the result will be zero. @Gothon mentioned that the editor or interpreter is assigning only
2 bytes4 bytes for the number you type in the editor. If you generate that number with a function like int() and pow() you get the right value into x and it will show correctly. (Hope i got that right) -
What if x was set to be 4294967295?
-
@toxibunny said in Unexpected fun (or fun facts):
What if x was set to be 4294967295?
You will get 4294967295 + 4294967295 = -2 because 4294967295 = 2^32 - 1. Valid values for 32 bit (4 byte) signed numbers go from -2^31 to 2^31 - 1 (-2147483648 to 2147483647), anything outside that range wraps around. Eg, 2147483648 = -2147483648
-
I asked my lawyer if it was a crime to throw Sodium Chloride at a person.
Lawyer: yes, it's assault
Me: I know it's a salt but is it a crime?!? -
So I told my boss there were some bugs in the server and he hired an exterminator to spray it down