Skip to content
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

Decimal.round updates #16

Merged
merged 2 commits into from
Apr 11, 2022
Merged

Decimal.round updates #16

merged 2 commits into from
Apr 11, 2022

Conversation

sarahghp
Copy link
Owner

I merged #14 earlier and then added my changes here instead of going back and forth. I am going to merge these as well, but feel free to comment on the PR still. Tomorrow my plan is to get actions up and building so we don't have to manually build and then see what I can add for the rest of the week.

},
};

const checkAndInitMathHandlers = (createUnaryHandler, createNaryHandler) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than leave this code unwrapped in patches.js, I think this check made it worth moving into its own file.

throw new Error(`Programmer error: patched Math method missing`);
}

PATCHED_MATH_METHODS.forEach((method) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never love doing this — the side-effecty forEach, the abstraction from the list of methods / table of contents approach, but I do think the handler check is probably worth it in this case.

};

function round(decimal, options = Object.create(null)) {
const round = (decimal, options = {}) => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updated this to match the way we are instantiation functions here. It's better to keep it consistent.


if (maximumSignificantDigits !== undefined) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposal does not currently support maximumSignificantDigits and I would rather keep it simple unless we hear a lot of requests for it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we shouldn't add things that are not in the proposal, but where are you seeing that it's not part of the proposal? There's no section header to link directly to, but it's in the Common elements section if you scroll down a bit.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ughhhh it's not listed in the specific references. I'm honestly tempted to leave it out because I don't really see the obvious need for two slightly different ways to round. And if there is clamor for it in its absence we've leaved something. At least through the magic of version control, the code is still referenceable so we haven't wasted your work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I've opened tc39/proposal-decimal#74 to audit for more of these discrepancies.

decimal,
maximumSignificantDigits,
internalMode
if (!(coercedFractionDigits >= 0)) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed from the check from undefined and then coercion with the unary plus to Number coercion and then the value because this way it catches null and empty strings and all sorts of things before the check.

},
});

const decimalOnlyBaseFn = (fnName) => () => {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the error-thrower as the target function is definitely inspired. I've abstacted it out here both so that we can use the name to explain what it's doing a bit and because I expect it's useful enough we'll see it again.

throw new Error(
`${what} not yet supported for ${implName}. Let us know if you need this! (https://github.com/tc39/proposal-decimal)`
`${what} is not yet supported for ${implName}. Let us know if you need this! (https://github.com/tc39/proposal-decimal)`
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also really love this error. Thank you!

@sarahghp sarahghp merged commit 18bf1a8 into website Apr 11, 2022
@sarahghp
Copy link
Owner Author

@ptomato FYI ⬆️

@sarahghp sarahghp deleted the decimal.round-updates branch April 13, 2022 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants