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

Config.epsilon doesn't seem to be working #3140

Closed
dvd101x opened this issue Jan 25, 2024 · 2 comments
Closed

Config.epsilon doesn't seem to be working #3140

dvd101x opened this issue Jan 25, 2024 · 2 comments
Labels

Comments

@dvd101x
Copy link
Collaborator

dvd101x commented Jan 25, 2024

On the current version V12.3.0, config.epsilon doesn't seem to be working.

The expected behavior is:

epsilon. The minimum relative difference used to test equality between two compared values. This value is used by all relational functions. Default value is 1e-12.

equal(0, 1e-13)    # false but should be true
equal(0, 1e-14)    # false but should be true
equal(0, 1e-15)    # false but should be true
equal(0, 1e-16)    # true

config({epsilon: 1e-3})  # {"epsilon": 0.001, "matrix": "Matrix", ...
equal(0, 1e-4)     # false but should be true
equal(0, 1e-6)     # false but should be true
equal(0, 1e-7)     # false but should be true
equal(0, 1e-15)    # false but should be true
equal(0, 1e-16)    # true

Regardless of config.epsilon, it's as if the value of epsilon was 2.220446049250313e-16

equal(0, 2.220446049250313e-16)     # true
equal(0, 2.220446049250314e-16)     # false
smallerEq(2.220446049250313e-16, 0) # true
smallerEq(2.220446049250314e-16, 0) # false

And it seems to be coming from this line of code.

export const DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16

I have not tested all relational functions but is seems consistent on the few I have tested.

Maybe it's also related to #3100

(Also tested V9.5.2, V10.6.4 and V11.12.0 with the same results)

@josdejong
Copy link
Owner

The nearly-equal comparison uses a relative equality. Comparing against zero is a special case.

Does this help: https://mathjs.org/docs/datatypes/numbers.html#equality?

@dvd101x
Copy link
Collaborator Author

dvd101x commented Jan 25, 2024

Yes, thank you very much.

My bad, didn't notice that comparing against 0 was a special case.

@dvd101x dvd101x closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants