ID:260345
 
number
proc
shiftleft(a,b)
return a << b
mob
verb
test()
var/number/n = new
var/result = n.shiftleft(1,25)
src << result


I thought byond numbers only have 16 bits of precision. I am clearly seeing more than that. As far as I understand byond represents numbers as floats and casts to an unsigned short int then back to a float to do bitwise operations. Can someone explain to me why I am getting more than 16 bits of precision?
I think it has to do with what the value is casted as when it is being operated on. For example, you can see a minimal version in the following snippet:

client/verb/Test()
var/a = 1 << 16 // 0
src << a

client/verb/Test2()
var/a = 1
src << (a << 16) // 65536

client/verb/Test3()
var/a = 1
a <<= 16 // 65536
src << a


I achieve a similar effect in ID:534870, where the first proc works with more hexadecimal digits than Lummox JR and most would have expected it to be able, as the bit-shifting is used in a way that allows for an undocumented, larger than 16-bit width.

Hiead
Datums are magic, plain and simple.
In response to Nadrew (#2)
Well are these being casted to regular ints or something? It does look there getting casted to regular ints, since when I shift a full 32 bits the number becomes negative like I shifted on the sign bit.
<dm>mob
verb
test()
var/a = 1
var/b = 1
while(a < 32)
a++
b += b
world << "[num2text(b,10000)] adding"
world << "[num2text((1 < I'm using this to test, can someone explain?
In response to Xx Dark Wizard xX (#3)
Dude, just RTFM and the source code if it matters that much. Oh yeah, you're using a closed toolkit, and have to rely on overworked developers to answer your questions. Tough luck there, man.

If you're doing mathematical work, I suggest using CLISP or PLT Scheme. They provide arbitrary numerical accuracy -- and if you're in doubt, you can check documentation and the source code to figure out exactly what is going on.
In response to PirateHead (#4)
If you're doing mathematical work, I suggest using CLISP or PLT Scheme.

While I do loves me some LISP, if you're doing "mathematical work" you should probably be using MATLAB or Mathematica.
In response to nick.cash (#5)
Yeah, it totally depends on the extent to which you need support for statistics packages and such... but I was already operating under the knowledge that he is using BYOND, which excludes the possibility of serious "mathematical work".