juantamad
Designing Elixir Systems Book Question
On page 23 of the book Designing Elixir Systems With Otp it says “Use div() and rem() to get integer division rather than /.”. For 7/6 gives 1.1666666666666667. How is div and rem better than 7/6?
Most Liked
JEG2
In the paragraph above your quote, we say, “… prefer integers or decimals over floats when you can.” This advice is based on the inaccuracy of floating-point arithmetic. If you want to follow our advice you need to avoid this problem:
iex(1)> 3 / 1
3.0
div/2 is how you do that.
NobbZ
It’s not about better or worse, it’s about “for integer division use div/rem, rather than / as the latter simply doesn’t do integer division but always returns a floating point number.”
NobbZ
It doesn’t say anything about using div/rem for floating point arithmetic, at least not in the portion you cite. There it just says that you can not use / for integer division…
Popular in Chat/Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








