Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #41104

Re: Are Floating Point Numbers still a Can of Worms?

Path csiph.com!news.mixmin.net!aioe.org!XakcSTEO51npqVb7OVl71w.user.46.165.242.75.POSTED!not-for-mail
From "R.Wieser" <address@not.available>
Newsgroups comp.lang.javascript
Subject Re: Are Floating Point Numbers still a Can of Worms?
Date Sat, 15 Oct 2022 16:31:04 +0200
Organization Aioe.org NNTP Server
Lines 78
Message-ID <tieg7a$5h9$1@gioia.aioe.org> (permalink)
References <31753076-4806-4dd3-8577-40a4ed23b57dn@googlegroups.com> <tie8s2$am5d$1@solani.org>
Injection-Info gioia.aioe.org; logging-data="5673"; posting-host="XakcSTEO51npqVb7OVl71w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Newsreader Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE Produced By Microsoft MimeOLE V6.00.2900.5512
X-Notice Filtered by postfilter v. 0.9.2
X-Priority 3
X-MSMail-Priority Normal
X-RFC2646 Format=Flowed; Response
Xref csiph.com comp.lang.javascript:41104

Show key headers only | View raw


Mostowski,

>I stepped over the example originally via Java and
> not JavaScript. I find the following discrepancy between
> JDK 19 and JDK 1.8, using Math.pow(), on Windows:
>
> /* JDK 1.8 Windows Nok */
> ?- X is 1889**29.
> X = 1.0250068783051206E95.
>
> /* JDK 19 Windows Ok */
> ?- X is 1889**29.
> X = 1.0250068783051207E95.
>
> ?- X is 1.0250068783051207E95-1.0250068783051206E95.
> X = 1.4821387422376473E79.

And what do you think you've proven there ?

may I also point out to you that the difference between E95 and E79 is about 
exactly the precision of a 64-bit float (~16 digits).    IOW, you are again 
trying to work with the least-significant bit in a 64-bit float.  And that 
that most always causes problems.   For instance, I would not at all be 
surprised when that last number is a simple power of two ...

I think Ben Bacarisse asked you a good question : what is the problem (that 
you seem to think you are seeing), and what has it to do with your 
subjectline ?

Regards,
Rudy Wieser

P.s.
I've got some numbers for you :

-- 1889*1889*1889*1889*1889* etc. calculated thru the FPU
53A891D176398773 - 1.0250068783051204e+095

The first part is the hexadecimal representation of the resulting 64-bit 
float, the latter part is how its represented when displayed for human 
consumption (thru fprint "%1.16f").   You might notice it ends on a 4 
instead of a 6.  This is likely because I didn't bother with any kind of 
"fixing up".   Adding 1 to the hexadecimal number gives your 6 result.

-- These below two are what I get when my program parses, and than displays 
the same two floats you gave in your current post.   It looks that my 
programming language (parsing the value and storing it in its binary form) 
does the same fixing-up JS does.

Notice that the hexadecimal representation shows a single point difference, 
just as the displayed human consumption numbers next to them.

53A891D176398774 - 1.0250068783051206e+095
53A891D176398775 - 1.0250068783051207e+095

Notice that both of the numbers you gave can be stored into the binary 
representation of a 64-bit float, and my suggestion that it might be a 
64-bit vs BigInt float doesn't seem to be the cause of the difference you're 
seeing.

Another possibility is that the rounding method (after calculation / 
parsing) between the two JDK versions has changed.  That /should/ be 
mentioned in the "whats changed" section.

-- This is the result of the subtraction of the above first from the second. 
As expected the hexadecimal representation shows the fractional part (the 
lower 22 bits) as all Zero.  Only the exponent part (bits 22 thru 30) 
contain some bits set to One.

5060000000000000 - 1.4821387422376473e+079

Bottom line :
1) The rounding method between two JDK versions seem to have changed.
2) The subtraction showing a large, seemingly "random" number is quite 
normal. (an effect similar to how decimal fractions cannot always be stored 
in a binary representation, but now the other way around).

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Are Floating Point Numbers still a Can of Worms? Mostowski Collapse <bursejan@gmail.com> - 2022-10-14 15:52 -0700
  Re: Are Floating Point Numbers still a Can of Worms? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-10-15 01:52 +0100
  Re: Are Floating Point Numbers still a Can of Worms? "R.Wieser" <address@not.available> - 2022-10-15 09:33 +0200
    Re: Are Floating Point Numbers still a Can of Worms? "R.Wieser" <address@not.available> - 2022-10-15 10:00 +0200
    Re: Are Floating Point Numbers still a Can of Worms? John Harris <niam@jghnorth.org.uk.invalid> - 2022-10-15 11:13 +0100
      Re: Are Floating Point Numbers still a Can of Worms? "R.Wieser" <address@not.available> - 2022-10-15 13:43 +0200
        Re: Are Floating Point Numbers still a Can of Worms? John Harris <niam@jghnorth.org.uk.invalid> - 2022-10-15 15:56 +0100
          Re: Are Floating Point Numbers still a Can of Worms? "R.Wieser" <address@not.available> - 2022-10-15 17:44 +0200
  Re: Are Floating Point Numbers still a Can of Worms? Mostowski Collapse <janburse@fastmail.fm> - 2022-10-15 14:25 +0200
    Re: Are Floating Point Numbers still a Can of Worms? "R.Wieser" <address@not.available> - 2022-10-15 16:31 +0200
      Re: Are Floating Point Numbers still a Can of Worms? John Harris <niam@jghnorth.org.uk.invalid> - 2022-10-15 16:22 +0100
        Re: Are Floating Point Numbers still a Can of Worms? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-10-15 17:04 +0100
          Re: Are Floating Point Numbers still a Can of Worms? Mostowski Collapse <bursejan@gmail.com> - 2022-10-15 09:47 -0700
            Re: Are Floating Point Numbers still a Can of Worms? Mostowski Collapse <janburse@fastmail.fm> - 2022-10-15 18:51 +0200
              Re: Are Floating Point Numbers still a Can of Worms? Mostowski Collapse <bursejan@gmail.com> - 2022-10-22 14:35 -0700
                Re: Are Floating Point Numbers still a Can of Worms? Mostowski Collapse <bursejan@gmail.com> - 2022-11-21 09:02 -0800
  Re: Are Floating Point Numbers still a Can of Worms? Julio Di Egidio <julio@diegidio.name> - 2022-10-17 02:00 -0700
    Re: Are Floating Point Numbers still a Can of Worms? Mostowski Collapse <bursejan@gmail.com> - 2022-10-18 07:40 -0700

csiph-web