Re:Fast midpoint between two integers without overflow
by hansvm on Wednesday December 07, 2022 @10:00AM
(#33895048)
Python, common lisp, and perl for starters.
[ Parent
| on HN ]
Re:Fast midpoint between two integers without overflow
by pacaro on Wednesday December 07, 2022 @11:35AM
(#33896439)
Also scheme and prolog
The problem you can then run into is that a mathematical operation can OOM
Re:Fast midpoint between two integers without overflow
by kazinator on Wednesday December 07, 2022 @10:05PM
(#33903626)
I've not seen this in practice.
You need some numeric accident involving a higher power operator like exponentiation.
In TXR Lisp I made exponentiation n-ary: you can do (expt x y z ...).
The associativity is right to left: it means
...
z
y
x
rather than the less useful cumulative exponentiation of the same base: yz...
x
which can easily be obtained as (expt x (* y z ..)).So, anyway, if you apply expt to small list of small operands, you can cons up a big number in rather a hurry.
If it is important to prevent a problem like this, a limit can be imposed on bignums (say, large enough for common cryptography to still work).
Re:Fast midpoint between two integers without overflow
by webstrand on Wednesday December 07, 2022 @10:30AM
(#33895463)
I didn't know python could do that, that's pretty cool.
I gotta disagree on perl, though, even though it can represent numbers outside of the range of a double, it can't manipulate them without converting them into doubles.