this post was submitted on 26 Feb 2024
751 points (95.7% liked)

Programmer Humor

19551 readers
1053 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Kissaki@programming.dev 2 points 8 months ago (1 children)

It doesn't have to "error" if the result case is offered and handled.

[–] Lmaydev@programming.dev 1 points 8 months ago (1 children)

Float processing is at the hardware level. It needs a way to signal when an unrepresented value would be returned.

[–] Ephera@lemmy.ml 2 points 8 months ago (1 children)

My thinking is that a call to the safe division method would check after the division, whether the result is a NaN. And if it is, then it returns an Error-value, which you can handle.

Obviously, you could do the same with a NaN by just throwing an if-else after any division statement, but I would like to enforce it in the type system that this check is done.

[–] Lmaydev@programming.dev 2 points 8 months ago* (last edited 8 months ago) (1 children)

I feel like that's adding overhead to every operation to catch the few operations that could result in a nan.

But I guess you could provide alternative safe versions of float operations to account for this. Which may be what you meant thinking about it lol

[–] Ephera@lemmy.ml 1 points 8 months ago

I would want the safe version to be the default, but yeah, both should exist. 🙃