-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add js BigInts #16409
Add js BigInts #16409
Conversation
We really need |
I know and the C/C++ too, still stuff gotta start somewhere... 🤷 |
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.
excellent!
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.
LGTM after addressing some comments.
Co-authored-by: flywind <[email protected]>
Co-authored-by: flywind <[email protected]>
Co-authored-by: flywind <[email protected]>
Co-authored-by: flywind <[email protected]>
Co-authored-by: flywind <[email protected]>
@Araq friendly ping on this, is there anything else needed? from my perspective every blocker was addressed, and the rest can be done in future PRs |
@juancarlospaco what was the reason again for: func `**`*(x, y: JsBigInt): JsBigInt {.importjs: "((#) $1 #)".}
# instead of
func `**`*(x, y: JsBigInt): JsBigInt {.importjs: "(# $1 #)".} ? import std/jsbigints
proc main()=
block:
var a = big"2"
var b = big"3"
var c = a ** b
echo c
block:
var c = [big"2"]
echo c[0] ** c[0]
main() this is also useful for the description of P3 in nim-lang/RFCs#315 |
The operator is introvert and shy, and likes to be surrounded by parenthesis. |
thanks, this helped. here's an even clearer explanation: the problem is when there's a unary operator func `**`*(x, y: int): int {.importjs: "((#) ** #)".}
func `***`*(x, y: int): auto = (x, y)
func `****`*(x, y: int): int {.importjs: "(# ** #)".}
proc id(a: auto): auto = a
doAssert id(-2 *** 3) == (-2, 3) # checks that - has higher precedence than ***
doAssert id(-2 ** 3) == -8 # ok
doAssert id(`****`(2, 3)) == 8
doAssert id(`****`(1+1, 3)) == 8
doAssert id(-2 **** 3) == -8 # # js error: SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence
# doAssert id((-2) **** 3) == -8 # ditto
# doAssert id(`****`((-2), 3)) == -8 # ditto
notefor # suppose someone adds this other proc that doesn't have ():
func neg(this: JsBigInt): JsBigInt {.importjs: "-#".}
let b = big"1"
echo (-b ** big"3") # works
echo (b.neg ** big"3") # js error |
@juancarlospaco 2nd question: you're using outer parens in all your importjs procs (eg: |
@juancarlospaco also, followup PR welcome for missing procs (eg: bitwise and, or) as mentioned by @xflywind |
Ah, I already make that PR :) |
* Add BigInts * Renames tos plurals * Improve Stringifications * Update changelog.md Co-authored-by: flywind <[email protected]> * RunnableExamplerize * discard the discardable pragma * Several improvements from peer reviews, more docs * More doc, more test * More doc, more test * Better error message 'Error: usage of low is an {.error.} defined at jsbigints.nim' instead of just 'type mismatch JsBigInt' * is an overload, rename * proc to scare kids away * Update lib/js/jsbigints.nim Co-authored-by: Timothee Cour <[email protected]> * nim-lang#16409 (comment) Co-authored-by: flywind <[email protected]> Co-authored-by: Timothee Cour <[email protected]>
runnableExamples
withdoAssert
,styleCheck
, changelog, documentation with links.