Open waldemarhorwat opened 3 weeks ago
Thanks for taking a look! I'll get to work on these issues. Stay tuned.
I added a sketch of how to fix things.
(This was unintentionally closed in #156 )
Thanks so much for this second round of detailed review! We plan to make changes to address almost all of your points below. Specifically:
EnsureDecimal128Value
with PickQuantum
is an excellent one, and we'll rewrite our algorithms in that form..compare
function (i.e., a function that can distinguish mathematically equal decimals). We don't have it for Number or BigInt, and people get by. You can use the coefficient or quantum accessors (which we will add) if you want to distinguish mathematically equal values.greaterThan
, lessThanOrEquals
, etc. are necessary to add, but they are easy to define; let's discuss the tradeoff in plenary. Our current thinking is to resurrect an earlier idea, of having a single, differentcompare
method, working with mathematical value, from which <, ≤, >, ≥ are trivially defined in user code.toString
algorithm to overflow to exponential notation using the same cutoffs Number uses.toString
with a separate operation that can be used just to convert a decimal value to an exact string that cleanly represents the decimal in a natural way, e.g., using exponential notation or trailing zero decimal points based on the quantum (e.g., could be "300", "3e2", or "300.00" depending on the member of the cohort, and may have 6000 zeroes after it).Thank you!
Some comments:
compare
method that compares mathematical values and returns one of {-1, 0, 1, NaN} is a very-nice-to-have.toString
threshold for switching to scientific notation should be higher than for Number due to Decimal128's higher precision. For Number we intentionally picked a threshold greater than its 17 digits of precision. Decimal128 offers 34 digits of precision, so it's reasonable to switch to scientific notation for large numbers when the magnitude exceeds 1034. When adding leading zeroes for small numbers, the same threshold as Number (10-6) seems fine.I added a proposed design of the methods for querying and working with exponents, significands, and the quantum, along with sample code for many use cases.
I took another look at the Decimal spec for the June meeting. The spec forms a good foundation, but I found some pervasive issues that make it self-contradictory or produce incorrect results and should be addressed before seeking stage 2.
My review follows. Some of the items are nontrivial and will require some discussion and agreement on how to fix. I'm offering to provide whatever help is needed to understand and fix these.
Confusion
Rounding
Quantum Handling
Canonicalization
Comparisons
Conversions
0
from0.0000
and0e75
.ECMAScript Mechanics
Decimal128("07")
throws.Missing Operations
Structure