To me this makes no sense since it is mathematically impossible for a whole number taken to the power of another whole number to have a fractional result.
Example:
will print
If I try to 'force it' to Integer...
...the result is:
..which is incorrect. There is no Round function, so how do I get around this almost-a-bug?
When I try 'Debug Pow(2,24)' in PureBasic I get:
'16777216.0' (which, although for some odd reason is still a float, is correct - And this is without using the Round() procedure).
So what's up? Can't these compilers see that all of the operands are integers, and therefore, the result should be, too?
Russell
Example:
For Local a = 0 To 31 Print 2 ^ a Next
will print
1.0000000000000000 2.0000000000000000 4.0000000000000000 7.9999999999999982 15.999999999999998 32.000000000000000 63.999999999999979 127.99999999999997 255.99999999999994 511.99999999999994 1024.0000000000000 2048.0000000000000 4095.9999999999968 8191.9999999999945 16383.999999999991 32767.999999999985 65535.999999999978 131071.99999999996 262143.99999999994 524287.99999999994 1048576.0000000000 2097152.0000000000 4194304.0000000009 8388608.0000000019 16777215.999999976 33554432.000000015 67108863.999999918 134217728.00000009 268435455.99999970 536870912.00000036 1073741823.9999990 2147483648.0000019
If I try to 'force it' to Integer...
For Local a:Int = 0:Int To 31:Int Print Int(2 ^ a) Next
...the result is:
1.0000000000000000 2.0000000000000000 4.0000000000000000 7.9999999999999982 15.999999999999998 32.000000000000000 63.999999999999979 127.99999999999997 255.99999999999994 511.99999999999994 1024.0000000000000 2048.0000000000000 4095.9999999999968 8191.9999999999945 16383.999999999991 32767.999999999985 65535.999999999978 131071.99999999996 262143.99999999994 524287.99999999994 1048576.0000000000 2097152.0000000000 4194304.0000000009 8388608.0000000019 16777215.999999976 33554432.000000015 67108863.999999918 134217728.00000009 268435455.99999970 536870912.00000036 1073741823.9999990 2147483648.0000019
..which is incorrect. There is no Round function, so how do I get around this almost-a-bug?
When I try 'Debug Pow(2,24)' in PureBasic I get:
'16777216.0' (which, although for some odd reason is still a float, is correct - And this is without using the Round() procedure).
So what's up? Can't these compilers see that all of the operands are integers, and therefore, the result should be, too?
Russell