5 ms·
The only way to achieve this is to either put a runtime software check on a variable whenever it's assigned/used, or to literally add hardware support in proces
by roadbuster 20d ago
The only way to achieve this is to either put a runtime software check on a variable whenever it's assigned/used, or to literally add hardware support in processors themselves which literally throws an interrupt when a "neverShallBeZero" variable is assigned to zero.
There's no viable way to statically prove at compile-time that these variables will never become zero at runtime, ultimately forcing a system of endless runtime checks (be it software or hardware)... which is why processors already throw exception interrupts when division by zero is attempted.
- colechristensen 20d agoYou're kind of saying the only way to do it is in software or hardware :) An alternative https://en.wikipedia.org/wiki/Projectively_extended_real_line https://en.wikipedia.org/wiki/Projectively_extended_real_lin... The projectively extended real line defines division by zero, no reason you couldn't have a floating point type that implemented it. >There's no viable way to statically prove at compile-time that these variables will never become zero at runtime strongly typed programming languages like Ada allow for types which have ranges such as disallowing zero -- but also any arbitrary thing like you can create a floating point "degrees" type which is [0.0, 360.0] or any other ranged type
- inigyou 20d agoIt's possible, just extremely difficult.