To be clear: both C++ and JS use the exact same "double" representation,
neither is more precise than the other. In fact we use the exact same
machine instructions to feel with them. The significant digits/decimal
digits mentioned are when printing, not when calculating.

So, if it's not x87 extra precision, then it must either be a non exact
translation from C++ to JavaScript, or a bug. If you have a small repro
that demonstrates the difference, then please file a bug and we'll take a
look.

- Leszek


On Wed, 26 Jun 2019, 06:00 Jerry Jin, <[email protected]> wrote:

> thank you, i googled around and found msvc double is using 64-bit sse, not
> x87 fpu
>
> not sure if it's because c++ double has 16 significant figures and js has
> 15
>
> On Tuesday, June 25, 2019 at 8:51:58 PM UTC+8, Jakob Kummerow wrote:
>>
>> If your original C++ code uses doubles, then porting it to
>> TypeScript/JavaScript should be possible without loss of accuracy (and
>> using plain built-in Numbers, no external libraries). If you have a
>> reproducible counter-example, it would be interesting to hear about the
>> details.
>>
>> The only exception I can think of is if your C++ compiler decided to emit
>> x87 FPU code (on x86 hardware) which would use 80 bits (instead of 64 bits)
>> for intermediate results. But I don't think modern compilers still do that;
>> they should emit 64-bit SSE instructions.
>>
>> Side note: modern JavaScript has BigInts, which have arbitrary precision,
>> but only integer values. So they're probably not useful for your case, but
>> depending on what problem you're solving, you might be able to reformulate
>> it to use integers.
>>
>>
>> On Tue, Jun 25, 2019 at 2:19 PM Dan Elphick <[email protected]> wrote:
>>
>>> On Tuesday, June 25, 2019 at 10:24:56 AM UTC+1, Jerry Jin wrote:
>>>>
>>>> Hello,
>>>> I'm new to v8-dev, sorry if this was already asked before.
>>>>
>>>> my problem is, i re-implemented a c++ numerical lib using typescript,
>>>> and some test cases failed due to float number not having enough accuracy
>>>> (i debugged js/c++ code side by side with chrome devtool&msvc)
>>>> right now, my only option is to user third party lib like `decimal.js`
>>>>
>>>> i wonder is there any way to increase float number accuracy like c++
>>>> double type?
>>>>
>>>
>>>> example, is there anyway to store more than 15 decimal places in number
>>>>
>>>
>>> Javascript and V8 already use doubles to represent floating point
>>> numbers. However double precision floating point numbers can have about 16
>>> significant figures, so it's not possible to get any more accuracy using
>>> C++ double. You may be able to print more than that (e.g. pi.ToFixed(30)
>>> but they won't be accurate beyond 15 decimal places.
>>>
>>>
>>>> ```
>>>> > let pi = 3.141592653589793238462643383280;
>>>> < undefined
>>>> > pi
>>>> < 3.141592653589793
>>>> ```
>>>>
>>>> not sure if this is possible in v8, if yes, where should i start?
>>>>
>>>> thanks!
>>>>
>>> --
>>> --
>>> v8-dev mailing list
>>> [email protected]
>>> http://groups.google.com/group/v8-dev
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-dev" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/v8-dev/cfed0633-c6e7-45c4-a5c0-ca9f6cfaec9a%40googlegroups.com
>>> <https://groups.google.com/d/msgid/v8-dev/cfed0633-c6e7-45c4-a5c0-ca9f6cfaec9a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> --
> v8-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-dev/bc1e8872-a93a-405b-94b7-0a8ad01e24f2%40googlegroups.com
> <https://groups.google.com/d/msgid/v8-dev/bc1e8872-a93a-405b-94b7-0a8ad01e24f2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAGRskv8U9OdWSq0K6-Qj-QX9-wjv1uWwPryO0e4-tWONVxJuDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to