-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: Uniformize bigint construction #3375
base: develop
Are you sure you want to change the base?
Conversation
Adds options to the bigint constructor function `math.bigint()` to control whether/how non-integer inputs are rounded or errors thrown, and whether "unsafe" values outside the range where integers can be uniquely represented are converted. Changes `math.numeric(x, 'bigint')` to call the bigint constructor configured to allow unsafe values but throw on non-integers (closest approximation to its previous buggy behavior). Also restores documentation generation for constructor functions, and initiates History sections in function doc pages. Resolves josdejong#3366. Resolves josdejong#3368. Resolves josdejong#3341.
OK, I have marked this as draft for two reasons:
Looking forward to your call here, then I can complete this PR to be ready for review. |
Thanks for putting together this draft PR. I think in general each factory function ( Right now, the rounding behavior of About the The improvements in the examples are nice. I'm not sure though why you have added indentation to some of the inline comments |
What facilities should we then provide to support a use that needs a bignumber but needs to avoid the creation of illusory precision where there is none? That is exactly our use case, and mathjs is generally supportive of avoiding spurious precision. So I am fine to change this particular signature, but we need a safety mechanism, and then I need to put it in this PR, since it was created and filed precisely to allow us to adopt v14 of mathjs, and our adoption is waiting on such a mechanism. Thanks for your advice/design here. |
I am fine of course with keeping the rounding config. The current behavior is |
I think History in the source file is much more maintainable than central history: you must edit the function's source file to make the change anyway, so you add a line to the History. Once every function has such a section, I think it will become very natural, and the reviewer can easily check it was done just by glancing at the diffs. However, if I need to augment this with an autoparser to get it merged, let me know and I will do it -- but I would recommend inserting the results in the source file in the History section so you can see them there and possibly tweak them; otherwise I think they are not going to come out very readable. |
It is because and only because the doc test ignores indented comments, and so a cheap way to fix a doc test that is failing because of free form comments that confuse its attempts to grab the expected return value of an expression is to just indent the comment. This behavior came from a number of pre-existing doc sections that used indented comments as sort of section headers. So the "ignoring indented comments" exception was already there, and I was using it to get more tests to pass. The goal of course is to get to all doc tests passing, at which point they can finally switch to being enforced. |
|
I personally would be happier with options on the conversion functions than new functions -- there are a lot of functions, which gets a bit unwieldy. This PR currently makes a Note there is a need for some safety mechanism for number => bigint as well as for bigint => number, because if someone tries to convert a
Yes, I get it. Happy to discuss in the history issue #3341. Does that mean you would like me to remove the History sections I added and the code that supported them from this PR, or should I leave them in as not doing any harm, and to keep around the information I generated, and they can always be massaged to the decided-on scheme later? Fine either way, just want to know what to do to get this PR in shape in the most direct way possible.
I will give it a try and let you know. |
…throws" Plus knock-on changes. This "simple" change unsurprisingly altered what doc tests occurred, leading to shaking out a bug in doc testing, which in turn shook out a bug in logical `and` (!). All should be well now. Also prevent `numeric(blah, 'bigint')` from throwing when it needs to round.
…fix/numeric_bigint
OK, got through this. Unsurprisingly (with the free form nature of doc comments) it was a bit more convoluted than
I will work on the last one ASAP and look forward to your feedback on the first two. |
(!) Ok yes let's go for a solution with (2) Thanks. Can you please remove the History sections from this PR? (maybe you can create a new temporary feature branch containing the current History sections for later reuse, so we don't throw away your work) (5) Nice that you managed to get the issue with example lines with comments solved 👍 |
Sure, I can add other safe options. Bigint => number safety is clear, as is BigNumber => number. But number => bignumber is much murkier. Nominally, every number can be exactly represented as a bignumber. But I think the "safety" you have in mind is not wanting 1.20000000001 to become a bignumber because it will make what seems to be roundoff error seem precise. I think we have discussed this before -- there is an algorithm for guessing whether a number comes from a precise rational number, based on continued fractions. But we didn't seem to reach consensus on this before. So my preference would be not to address that type of safety in this pr lest it becomes bogged down. |
OK I have moved the History work to a branch feat/function_history in the main repo. |
Thanks!
Yes agree, let's adress those ideas in an other PR 👍 |
The relevant discussion is in #1485. |
Slightly confused: am implementing the |
Adds options to the bigint constructor function
math.bigint()
tocontrol whether/how non-integer inputs are rounded or errors thrown,
and whether "unsafe" values outside the range where integers can be
uniquely represented are converted. Changes
math.numeric(x, 'bigint')
to call the bigint constructor configured to round and to allow unsafe
values.
Also restores documentation generation for constructor functions.
and initiates History sections in function doc pagesResolves #3366.
Resolves #3368.
Resolves #3341.