Big integer, Big float, and operator overloading ideas
kaizhu256 at gmail.com
Mon May 28 18:08:10 UTC 2018
oh, also i'm not a tc39 member if i made it sound like i was ^^;;;
kaizhu256 at gmail.com
> On 29 May 2018, at 1:43 AM, kai zhu <kaizhu256 at gmail.com> wrote:
> hi fabrice, what you’ve done is interesting and impressive; but an integration-level concern (if tc39 is to consider standardizing your extension, rather than keep it userland) is how would a web-project go about baton-passing these arbitrary-precision numbers between browser <-> server <-> persistent-storage via JSON? what would happen if you pass an arbitrarily large float as a “number” type to current mysql (or native-module sqlite3) driver?
> playing with your live web-demo @ http://numcalc.com/ <http://numcalc.com/>, it seems JSON.stringify has divergent behavior between math-equivalent large floats (preserves full-precision) and large integers (throws error as a bigint):
> mjs > 12345678901234567890.0e0 === 12345678901234567890
> mjs > typeof 12345678901234567890.0e0
> mjs > JSON.stringify(12345678901234567890.0e0)
> mjs > typeof 12345678901234567890
> mjs > JSON.stringify(12345678901234567890)
> TypeError: bigint are forbidden in JSON.stringify
> at to_str (stdlib.js)
> at stringify (stdlib.js)
> at <eval> (<evalScript>)
> at evalScript (native)
> at eval_and_print (repl.js)
> at setPrec (native)
> at handle_cmd (repl.js)
> at readline_handle_cmd (repl.js)
> at handle_key (repl.js)
> at handle_char (repl.js)
> at handle_byte (repl.js)
> mjs > JSON.parse(JSON.stringify(1.12345678901234567890123456789e123456))
> 1.12345678901234567890123456789e+123456 // takes ~200ms to process
> mjs > JSON.parse(JSON.stringify(1.12345678901234567890123456789e-123456))
> 1.12345678901234567890123456789e-123456 // takes ~200ms to process
> mjs > JSON.stringify(1.1e1234567890) // unresponsive
> mjs > JSON.stringify(1.1e-1234567890) // unresponsive
> kai zhu
> kaizhu256 at gmail.com <mailto:kaizhu256 at gmail.com>
>> On 28 May 2018, at 7:25 PM, Fabrice Bellard <fabrice at bellard.org <mailto:fabrice at bellard.org>> wrote:
>> 1) Overloading of the standard operators to support new types such as complex numbers, fractions or matrixes.
>> 2) Bigint mode where arbitrarily large integers are available by default (no "n" suffix is necessary as in the BigInt proposal at https://tc39.github.io/proposal-bigint/ <https://tc39.github.io/proposal-bigint/> ).
>> 3) Arbitrarily large floating point numbers in base 2 using the IEEE 754 semantics.
>> 4) Optional "math" mode which modifies the semantics of the division, modulo and power operator. The division and power operator return a fraction with integer operands and the modulo operator is defined as the Euclidian remainder.
>> es-discuss mailing list
>> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss