diff options
author | metagn <metagngn@gmail.com> | 2023-04-11 22:20:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-11 21:20:20 +0200 |
commit | f05387045df55bf7123ee68002238e943716815e (patch) | |
tree | 9ba7959434162830612e31351eadbae79cf3bc37 /lib/std | |
parent | be06446ffecd7665651a25d6b07fade5cc019296 (diff) | |
download | Nim-f05387045df55bf7123ee68002238e943716815e.tar.gz |
int64/uint64 as bigint in JS (#21613)
* int64/uint64 as bigint in JS * fix CI * convert to compile option * fix lie * smaller diff, changelog entry
Diffstat (limited to 'lib/std')
-rw-r--r-- | lib/std/exitprocs.nim | 2 | ||||
-rw-r--r-- | lib/std/jsbigints.nim | 4 | ||||
-rw-r--r-- | lib/std/private/jsutils.nim | 17 |
3 files changed, 19 insertions, 4 deletions
diff --git a/lib/std/exitprocs.nim b/lib/std/exitprocs.nim index 48b4fca7f..36f22a5d1 100644 --- a/lib/std/exitprocs.nim +++ b/lib/std/exitprocs.nim @@ -10,6 +10,8 @@ ## This module allows adding hooks to program exit. import locks +when defined(js) and not defined(nodejs): + import std/assertions type FunKind = enum kClosure, kNoconv # extend as needed diff --git a/lib/std/jsbigints.nim b/lib/std/jsbigints.nim index 04578fc87..fda299e7b 100644 --- a/lib/std/jsbigints.nim +++ b/lib/std/jsbigints.nim @@ -64,10 +64,10 @@ func wrapToUint*(this: JsBigInt; bits: Natural): JsBigInt {.importjs: runnableExamples: doAssert (big("3") + big("2") ** big("66")).wrapToUint(66) == big("3") -func toNumber*(this: JsBigInt): BiggestInt {.importjs: "Number(#)".} = +func toNumber*(this: JsBigInt): int {.importjs: "Number(#)".} = ## Does not do any bounds check and may or may not return an inexact representation. runnableExamples: - doAssert toNumber(big"2147483647") == 2147483647.BiggestInt + doAssert toNumber(big"2147483647") == 2147483647.int func `+`*(x, y: JsBigInt): JsBigInt {.importjs: "(# $1 #)".} = runnableExamples: diff --git a/lib/std/private/jsutils.nim b/lib/std/private/jsutils.nim index 836b3512a..fd1f395f3 100644 --- a/lib/std/private/jsutils.nim +++ b/lib/std/private/jsutils.nim @@ -79,5 +79,18 @@ when defined(js): assert not "123".toJs.isSafeInteger assert 123.isSafeInteger assert 123.toJs.isSafeInteger - assert 9007199254740991.toJs.isSafeInteger - assert not 9007199254740992.toJs.isSafeInteger + when false: + assert 9007199254740991.toJs.isSafeInteger + assert not 9007199254740992.toJs.isSafeInteger + +template whenJsNoBigInt64*(no64, yes64): untyped = + when defined(js): + when compiles(compileOption("jsbigint64")): + when compileOption("jsbigint64"): + yes64 + else: + no64 + else: + no64 + else: + no64 |