-
Notifications
You must be signed in to change notification settings - Fork 2
Update README.md #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update README.md #102
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1 +1,20 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # rain.math.float | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Decimal floating point math implemented in Solidity/Yul. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## Context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IEEE 754 Floating point math such as is used by JavaScript is usually bad in finance for a few reasons. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - The decimal representations of amounts and prices of things don't have exact representations in the underlying binary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Mathematical nonsense like dividing by 0 gives "special" values like `Infinity` and `NaN` which then propagate throughout business logic rather than erroring | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This lib provides decimal floats that do error upon nonsense. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Everything you can type into a webform, or Rainlang, etc. that fits into 224 bit coefficient with 32 bit exponent (huge values for both) will be exactly represented. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This doesn't mean the floating point math is perfect, for example 1/3 will still be some imprecise rounded 0.3333... value as we don't have infinite precision. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| It does mean that `0.2+0.7` is `0.9` rather than `0.8999999999999999` because the fractional values use decimal exponents rather than binary exponents. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| e.g. `0.2` internally is something like `2e-1` and `0.7` is `7e-1` so internally the result is `2+7` which is `9` with an exponent of `-1`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Tighten wording, fix hyphenation/grammar, and clarify behavior; propose an editorial pass Suggested rewrite improves clarity, tone, and technical precision (hyphenation, spacing, and neutral language), and aligns with the library’s decimal exponent and bit‑layout design. -Decimal floating point math implemented in Solidity/Yul.
+Decimal floating‑point math implemented in Solidity/Yul.
## Context
-IEEE 754 Floating point math such as is used by JavaScript is usually bad in finance for a few reasons.
+IEEE 754 binary floating‑point (as used by JavaScript) is a poor fit for many financial use cases:
-- The decimal representations of amounts and prices of things don't have exact representations in the underlying binary
-- Mathematical nonsense like dividing by 0 gives "special" values like `Infinity` and `NaN` which then propagate throughout business logic rather than erroring
+- Many decimal fractions cannot be represented exactly in binary floating‑point formats.
+- Operations such as division by zero produce special values (`Infinity`, `NaN`) that can propagate through computations instead of reverting.
-This lib provides decimal floats that do error upon nonsense.
+This library provides decimal floats that revert on invalid operations rather than producing `NaN`/`Infinity`.
-Everything you can type into a webform, or Rainlang, etc. that fits into 224 bit coefficient with 32 bit exponent (huge values for both) will be exactly represented.
+Any finite decimal literal whose coefficient fits within 224 bits with a 32‑bit decimal exponent range is exactly representable in this format. Internally, the `Float` type packs a 224‑bit signed coefficient and a 32‑bit signed exponent into 32 bytes.
-This doesn't mean the floating point math is perfect, for example 1/3 will still be some imprecise rounded 0.3333... value as we don't have infinite precision.
+Not all values have exact decimal expansions; for example, 1/3 will be rounded (0.3333…), as precision is finite.
-It does mean that `0.2+0.7` is `0.9` rather than `0.8999999999999999` because the fractional values use decimal exponents rather than binary exponents.
+It does mean that `0.2 + 0.7` evaluates to `0.9`, because fractional values use base‑10 exponents rather than base‑2 exponents.
-e.g. `0.2` internally is something like `2e-1` and `0.7` is `7e-1` so internally the result is `2+7` which is `9` with an exponent of `-1`.
+For example, `0.2` is represented approximately as `2e-1` and `0.7` as `7e-1`; adding them yields `9e-1` (i.e., `0.9`).📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[grammar] ~3-~3: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~3-~3: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [grammar] ~5-~5: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [uncategorized] ~7-~7: If this is a compound adjective that modifies the following noun, use a hyphen. (EN_COMPOUND_ADJECTIVE_INTERNAL) [grammar] ~7-~7: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~7-~7: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~7-~7: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [grammar] ~9-~9: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~10-~10: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~10-~10: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~12-~12: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [grammar] ~14-~14: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) [grammar] ~14-~14: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~14-~14: Use proper capitalization (QB_NEW_EN_OTHER_ERROR_IDS_6) [grammar] ~14-~14: Use proper capitalization (QB_NEW_EN_OTHER_ERROR_IDS_6) [grammar] ~14-~14: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [grammar] ~16-~16: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~16-~16: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~16-~16: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~16-~16: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~16-~16: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [grammar] ~18-~18: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN) 🤖 Prompt for AI Agents
Comment on lines
+18
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Great illustrative example—keep it, just minor spacing/notation polish The 0.2 + 0.7 example is valuable and correctly motivates decimal exponents; the suggested edit above only adds spacing and a clearer “For example” sentence. 🧰 Tools🪛 LanguageTool[grammar] ~18-~18: Use correct spacing (QB_NEW_EN_OTHER_ERROR_IDS_5) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN_OTHER) [grammar] ~20-~20: There might be a mistake here. (QB_NEW_EN) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider adding follow-ups: API links and behavior specifics
Given maintainer preference to iterate docs via issues, propose opening issues to add:
I can draft these issues with checklists if you want.
🧰 Tools
🪛 LanguageTool
[grammar] ~5-~5: Use correct spacing
Context: ...implemented in Solidity/Yul. ## Context IEEE 754 Floating point math such as is ...
(QB_NEW_EN_OTHER_ERROR_IDS_5)
🤖 Prompt for AI Agents