4 ms·
Doesn't Ada have this ability where you define numeric types with a range?
by jgibson 8y ago
Doesn't Ada have this ability where you define numeric types with a range?
- MaxLeiter 8y agoYes, like so type jump_by_tenth is delta 0.1 range 1.0 .. 99.0;
- adrianN 8y agoYes but afaik it translates to runtime checks.
- red75prime 8y agoIt cannot be done in compile-time in general case. Rice's theorem forbids. Every non-trivial property of a program (like whether result of this function lies in this range for all inputs in that range) is undecidable. ETA: I'm not completely correct. Ada could have used something akin to 2-complement overflow handling, that is forcing every operation on a range to have a result in the same range, but it introduces runtime overhead too.