logoalt Hacker News

hyperhellotoday at 2:54 AM3 repliesview on HN

Okay,

int integer_division(int a, int b) { if (b!=0) return a/b; raise(SIGFPE); }

Great.


Replies

derditoday at 8:16 AM

No. In this type of language, the typical division function does not check against zero. It has a precondition that requires the caller to ensure that the divisor is not zero. If the data the caller has is completely arbitrary, then yes, the caller must use an if statement or similar. If the caller knows something about its data and can be sure that the divisor is not zero, then it doesn't need to use an if statement. But it might need to convince the proof checker that it knows what it's doing.

rdevillatoday at 3:10 AM

You don't appear to understand the difference between runtime and static analysis/compile time, or term-level and type-level.

show 1 reply