3 ms·
> then discover that for simple examples you run out of machine bits Why? I don't think it would be common to run out of machine bits for correct programs (and
by zzzcpan 10y ago
> then discover that for simple examples you run out of machine bits
Why? I don't think it would be common to run out of machine bits for correct programs (and not really run out, just go into bigints in some cases). But the compiler cannot calculate those bits based on machine types, instead it should track all possible values/ranges and multiply them too to decide whether the result could fit into the type or it needs a bit bigger one. And since values don't appear out of thin air, but come from literals or some input and checked for specific ranges all the time, it should be possible to automatically choose appropriate types and only warn about possible overflows or performance penalties due to bigints.
Naive approach of multiplying machine types is pointless, of course, on that I agree.
- AstralStorm 10y agoGenerally, for fixed point operation you need to explicitly handle two things: overflow and rounding. The former may not be an issue in some applications, but the latter will. It is easy to introduce a cumulative error by incorrect rounding for instance.
- zzzcpan 10y agoI suppose rounding is solvable too. Depending of how value is used at the end it would be possible to deduce how much precision is needed to guarantee no cumulative error.