134
submitted 5 months ago by abhi9u@lemmy.world to c/technology@lemmy.world
you are viewing a single comment's thread
view the rest of the comments
[-] Ephera@lemmy.ml 3 points 5 months ago

Unfortunately, that's not what it's about.

With Rust's language design¹, one could easily forbid ever comparing two floats via the normal operators (not just for literals), but they decided to allow that nonetheless. I'm guessing, because it would just be too annoying for generic implementations, if you'd always need special treatment for floats.

Rather, what I was referring to, is that they've split partial ordering and partial equality from their total variants. And integers are marked that they can do total equality and total ordering, whereas floats are not.

Honestly, it doesn't come up a lot, but I know for example, if you want to use something as a key in a HashMap, it needs to have total equality.
And in a BTreeMap (basically a binary tree, i.e. keys are inserted in a sorted manner), total ordering is required for the keys.

¹) Basically, comparison is typed and each type needs to opt into comparison with any type it wants to be compared to. So, if you define a new data type, then by default you cannot ask it whether it's equal to or less/more than anything else.

this post was submitted on 27 May 2024
134 points (94.1% liked)

Technology

59147 readers
2263 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related content.
  3. Be excellent to each another!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, to ask if your bot can be added please contact us.
  9. Check for duplicates before posting, duplicates may be removed

Approved Bots


founded 1 year ago
MODERATORS