practicalli / practicalli/clojure
Mathematical precision - floats and big decimal
Nobody has claimed this yet.
- Dominant language
- Makefile
- Stars
- 117
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
;; vinurs 01:19
;; how can i make
(+ 0.3 0.6)
;; equal to 0.9?
;; and
(+ 0.2 0.1)
;; equal => 0.30
;; quick answer is, use bigdecimal
(+ 0.3M 0.6M)
Most floating point numbers (Java type float and double, based on IEEE 754 standard) are approximations. This section of the Clojure equality guide article might have some useful info: https://clojure.org/guides/equality#_floating_point_numbers_are_usually_approximations
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the issue examples and the linked Clojure equality guide section on floating-point approximations. Locate the relevant documentation section in this repository, then document why the arithmetic results differ and how BigDecimal literals address the examples shown. Done means the explanation and examples are clear and accurate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100