4 ms·
> If I ever create a programming language, one thing I'd like to try is to promote integer operations to larger types, so there is never overflow. Are there an
by gumby 4y ago
> If I ever create a programming language, one thing I'd like to try is to promote integer operations to larger types, so there is never overflow.
Are there any languages other than Lisp and Python that have automatic bignum support?
- fulafel 4y agoPike, Haskell. Clojure makes a gesture toward it, literals are automatically promoted but the normal operators don't do it: user=> (+ 1 9223372036854775807) ;; max signed int64 Execution error (ArithmeticException) at user/eval5 (REPL:1). integer overflow user=> (+ 1 9223372036854775808) ;; one higher 9223372036854775809N
- eesmith 4y agoTcl. In tclsh: % expr 1 + 9223372036854775807 9223372036854775808 % expr 9223372036854775808 + 1 9223372036854775809
- tudorpavel 4y agoRuby's Integer type works like BigInteger under the hood.
- arh68 4y agoErlang's got them, I'm pretty sure.
- OkayPhysicist 4y agoYep, integers on the BEAM are unbounded, since the language was built with "This program will run forever" as a design concern. Indices capping out and causing crashes was not an acceptable state of affairs.
- ErikCorry 4y agoDart initially had it, but JS compatibility was more important. However they don't have JS compatibility either (Dart does not round off large integers like JS does), so I forget what the point was. Dart also (very early) had infinite precision fractions. So if you divided 355 by 113 you didn't get 3 or 3.1415... you got the fraction 355/133 which was an instance of a first class numeric type. Unfortunately this means your numbers can grow to need arbitrary amounts of storage in loops.
- gumby 4y agoCommonlisp has rationals as well (355/133) though division doesn't generate them by default.