Closed glennj closed 5 months ago
test_equal("grains on square 64",9223372036854775808, square(64))
fails with
failed: grains on square 64, expected: -9.22337203685478e+18 but got: 9.22337203685478e+18
Hey @ghaberek @petelomax why?
See https://openeuphoria.org/forum/137540.wc#137540
I've fixed this in Phix so I don't care, so there :-)
2^63 is too big an integer for euphoria to handle. Big floats are OK though:
test_equal("grains on square 64", 9223372036854775808.0, square(64))
passes
passed: grains on square 64
I am surprised Euphoria doesn't automagically promote the too-big-int to a float.
shift_bits() is defined in std/math.e and for reasons no doubt lost in the mists of time (and nothing to do with me!) it insists on and_bits(source_number, 0xFFFFFFFF) not just once but twice, which will obviously limit what it can return and probably mess up the sign bit (though that may just be a Phix thing). My advice would be to take a (renamed) copy of that to play with.
While it won't help you, Phix has builtin << and >> operators, implemented as lhs*power(2,rhs) and floor(lhs/power(2,rhs)) respectively, which are not only a tad more efficient by being inlined, but also don't impose any 32-bit limits. By inlined I just mean the front-end emits the exact same IL it would were the longhand versions found in the source code.
I am surprised Euphoria doesn't automagically promote the too-big-int to a float. Lots of rough edges on this language. Have a chat to @ghaberek about its long and circuitous history. Greg's working on v4.2. I'm expecting a lot of @petelomax's fixes for Phix will end up in the final product.
Addressed in https://github.com/exercism/euphoria/pull/61
The test file gives away the implementation
I wanted to solve it with bitwise functions, but hit the 32-bit integer limit
This exercise could use an
instructions.append.md
talking about Euphoria's number types.