-
Notifications
You must be signed in to change notification settings - Fork 120
Comprehensive jsnum tests #1818
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
base: horizon
Are you sure you want to change the base?
Conversation
…t exercised by Pyret
- fromString(): for non-negative-exp sci not, avoid a division
- js-numbers.js returns _innards to allow more testing
- liftFixnumInteger: should produce valid Rational boxnum
- add test for toRepeatingDecimal
- test toStringDigits
- correct isInteger() def
tests/jsnums-test/jsnums-test.js
Outdated
expect(JN.fromString("1e140", sampleErrorBacks)).toEqual(JN.makeBignum("1e140")); | ||
|
||
// for large bignums (> 1e140 ?), fromString() and makeBignum() can give structurally | ||
// unequal results. so the following fail: |
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.
@ds26gte why are these commented out? We should be testing to make sure they fail, right?
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.
The idea is that they should not fail, but were. I kept them around so I could solve the underlying problem as to why they were failing.
Now that I've canonicalized bigint representation -- i.e, every bigint now has a only one representation, not multiple as before --, these tests no longer fail, and are now uncommented.
- ensure integerNthRoot() is monotonically nondecreasing brownplt#1822 - require integerNthRoot() root and radicand to be non-neg - require nthRoot() root to be non-neg
** should remove fields at .t and above ** should remove any trailing zero fields, also reducing .t - bnDivide() should call clamp()
- test: bnToString _integerIsZero _integerIsOne _integerGcd
- bnpD{L,R}ShiftTo() should canonicalize
- test for: makeInteger{UnOp,Binop} - test for: bnpAddTo bnpDMultiply bnpMillerRabin - test for: bnRemainder bnModPow bnDivideAndRemainder bnIsProbablePrime
While adding tests, found the following corrections that needed to be applied to
|
- toRational() methods take errbacks param even tho they don't use them
going the fixnum route. (This is because in JS tests, it is possible to call these methods specifically, and they shouldn't bail unnecessarily.) - test-numbers.js: confirm num-log(VERYBIGINT) converges - jsnum-tests.js: confirm log() of VERYBIGINT and VERSMALLRAT converge
- runtime.js charts-lib.js image-lib.js internal-image-types.js internal-image-untyped.js make-image.js: ensure jsnums.{toFixnum,greaterThan,lessThan,roughlyEquals} calls take NumberErrbacks
Made all these changes and some more too. Also checked for and added errbacks to calls in files that import jsnums, viz., runtime.js, charts-lib.js, image-lib.js, internal-image-typed.js, internal-image-untyped.js, make-image.js. Most of the changes in these files have to do with toFixnum(). FYI: code.pyret.org has many such calls, which we have the option of fixing in a code.pyret.org PR. Also, let me know if we should consider scrubbing the unused HAC functions (which I have identified with a comment). There are 15 of them and they define methods on BigInteger that (a) don't have counterparts in the other boxnums, and (b) aren't used even as BigInteger methods. They are dead code. |
Please don't remove the unused HAC functions yet; if anything that should be a separate PR, but it's low priority at most. Regarding
I think a bunch of js-number's exported functions would benefit from this:
So e.g.
Then the call-sites of these functions can stay unchanged and simple, but the internal implementation always has an errbacks to pass through. (This should also change e.g. line 1484) I think this would avoid the need for a matching PR in CPO to change all the callsites of Speaking of, there are missing errbacks on lines 1919--1942, in the calls to |
Amen. I'm totally for this, but we seemed to have been biased toward adding errbacks rather than removing it. Existing code (even before the PR) does however already use errbacks for In this regard, please note that we have arithmetic-function generators |
…invoked - toFixnum() function doesn't take errbacks - boxnum toFixnum() methods do - toFixnum() function passes InternalCompilerErrorErrbacks to boxnum toFixnum() methods
Where will |
…ilerErrorErrbacks to its methods - 〃 for numerator(), denominator() - Replace previous use of {} as dummy errbacks with InternalCompilerErrorErrbacks - Ensure Roughname.makeInstance() calls take errbacks
…erErrorErrbacks to its methods
Here are some functions in js-numbers.js that take errbacks.
The following functions dispatch to boxnum methods. They can probably lose their errbacks parameter but call the related boxnum methods with
The following don't correspond to boxnum methods. They should probably
|
It can't. Its fields could be mapped to a function like (using @blerner's template):
|
- add test for InternalCompilerErrorErrbacks
- makeIntegerUnOp's args and results (_integerIsZero _integerIsOne _integerIsNegativeOne) don't take errbacks
While chasing errbacks on
which seems to not take advantage of I think it's better simplified as
This is the case for all four of the number comparison functions. I can't tell what the intent behind the original complication was. |
The I don't know why |
P.S. All but one use of (The one makeNumericBinop that is used without open-coding part of its functionality is |
(This should probably be addressed in a different PR) This reverts commit 38b91c6.
This in-progress PR addresses Issue #1812.
A JS test file
tests/jsnums-test/jsnums-test.c
will test the methods and functions defined injs-numbers.js
(Pyret's number library) that cannot be adequately tested by Pyret test files such astests/pyret/tests/test-numbers.js
.This PR is WIP, and not ready to merge yet.