top | item 42293753

(no title)

jsnedjdn | 1 year ago

Never have I ever met anybody who would think dividing by zero yields zero O_o

If anything it feels natural to yield +/-infinity

discuss

order

giraffe_lady|1 year ago

It's not about what I think zero division yields I've taken a math class before. It's just about representation within the type system. If division can return infinities we can't safely combine division with other functions that are expecting ints and floats.

Most languages throw an error instead, but there are tradeoffs there too. If you've decided not to throw an error you should at least return a usable number and zero makes more sense than -1 or 7 or a billion or whatever.

You could also build the number stack from the ground up to accommodate this edge case, and make it so all arithmetic functions can handle infinities, infinitesimals and limits. I've come across a racket sublang like that but it's nearly unusable for the normal common things you want to do with numbers in code.

ctenb|1 year ago

NaN is a valid float, so are infinities