|
|
Subscribe / Log in / New account

Integer overflow

Integer overflow

Posted Apr 30, 2013 9:11 UTC (Tue) by etienne (guest, #25256)
In reply to: Integer overflow by k8to
Parent article: A taste of Rust

> Python for example just overflows integers

I wonder if a language exists which separate "data" and "counter" variables, and associates every "data" with a unit - considering counters do not tend to overflow.
When a "data" overflow, it would then change the unit to something more appropriate.
For instance, if a variable contains "300 millimetres" and I multiply it by 10^9, the resulting variable would not contain 0x2BA7DEF3000 millimetres but 300000 meters.
Obviously it can be bad in some rare cases, but it would also have a lot of advantages: you can compare "data" variables in different compatible units (miles and kilometres, degree Fahrenheit and Celsius, joules and calories...) and it could deduce the unit of calculus (divide miles by hours and compare it to meters per second) and flags errors (compare kilowatt per hours to Amperes)...


to post comments

Integer overflow

Posted Apr 30, 2013 13:43 UTC (Tue) by mathstuf (subscriber, #69389) [Link]

The second part has been implemented (see boost::unit). I don't believe that the first part has been in any of the unit libraries I've seen (they are mostly compile-time constructs and just reduce to doubles).

Integer overflow

Posted May 1, 2013 15:03 UTC (Wed) by dark (guest, #8483) [Link]

The first part is basically what floating point math is :)


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds