Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38400 > unrolled thread
| Started by | j4n bur53 <janburse@fastmail.fm> |
|---|---|
| First post | 2018-06-24 20:41 +0200 |
| Last post | 2018-06-26 10:29 -0700 |
| Articles | 8 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
Has Android different floats? j4n bur53 <janburse@fastmail.fm> - 2018-06-24 20:41 +0200
Re: Has Android different floats? Arne Vajhøj <arne@vajhoej.dk> - 2018-06-24 15:21 -0400
Re: Has Android different floats? bursejan@gmail.com - 2018-06-24 13:31 -0700
Re: Has Android different floats? bursejan@gmail.com - 2018-06-24 13:35 -0700
Re: Has Android different floats? bursejan@gmail.com - 2018-06-24 13:44 -0700
Re: Has Android different floats? Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-06-24 17:28 -0400
Re: Has Android different floats? bursejan@gmail.com - 2018-06-24 16:08 -0700
Re: Has Android different floats? bursejan@gmail.com - 2018-06-26 10:29 -0700
| From | j4n bur53 <janburse@fastmail.fm> |
|---|---|
| Date | 2018-06-24 20:41 +0200 |
| Subject | Has Android different floats? |
| Message-ID | <pgool7$bru$1@news.albasani.net> |
Dear All, Running a simple test. ** is Math.pow(), ^ is BigInteger.pow() and then BigInteger.doubleValue(). On Java: ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true. 15-0.0 16-0.0 17-0.0 18-0.0 19-0.0 20-0.0 21-0.0 22-0.0 23-1.6777216E7 24-0.0 25-0.0 26-0.0 27-0.0 28-0.0 29-0.0 30-0.0 On Adroid: ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true. 15-0.0 16-0.0 17-0.0 18-0.0 19-0.0 20-0.0 21-0.0 22-0.0 23-0.0 24-0.0 25-0.0 26-0.0 27-0.0 28-0.0 29-1.7592186044416E13 30-0.0 Has Android different floats? Tested jdk1.8.0_152 against Android 8.0.0 Best Regards
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2018-06-24 15:21 -0400 |
| Message-ID | <pgor09$19ak$1@gioia.aioe.org> |
| In reply to | #38400 |
On 6/24/2018 2:41 PM, j4n bur53 wrote: > Running a simple test. > ** is Math.pow(), > ^ is BigInteger.pow() and then BigInteger.doubleValue(). > > On Java: > > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true. > 15-0.0 > 23-1.6777216E7 > 29-0.0 > 30-0.0 > > On Adroid: > > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true. > 15-0.0 > 23-0.0 > 29-1.7592186044416E13 > 30-0.0 > > Has Android different floats? > Tested jdk1.8.0_152 against Android 8.0.0 ARM supposedly use standard IEEE 754 FP. But I wonder if usage of strictfp would change your results. Arne
[toc] | [prev] | [next] | [standalone]
| From | bursejan@gmail.com |
|---|---|
| Date | 2018-06-24 13:31 -0700 |
| Message-ID | <b4f7eefd-bde4-4b77-9dbf-b417091061ed@googlegroups.com> |
| In reply to | #38401 |
You cannot use the strictfp keyword in front
of Math.pow(). Thats only for the basic operations.
Math.pow() itself is implemented in JDK 1.8 as follows:
public static double pow(double a, double b) {
return StrictMath.pow(a, b); // default impl. delegates to StrictMath
}
Am Sonntag, 24. Juni 2018 21:21:57 UTC+2 schrieb Arne Vajhøj:
> On 6/24/2018 2:41 PM, j4n bur53 wrote:
> > Running a simple test.
> > ** is Math.pow(),
> > ^ is BigInteger.pow() and then BigInteger.doubleValue().
> >
> > On Java:
> >
> > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
> > 15-0.0
>
> > 23-1.6777216E7
>
> > 29-0.0
> > 30-0.0
> >
> > On Adroid:
> >
> > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
> > 15-0.0
>
> > 23-0.0
>
> > 29-1.7592186044416E13
> > 30-0.0
> >
> > Has Android different floats?
> > Tested jdk1.8.0_152 against Android 8.0.0
>
> ARM supposedly use standard IEEE 754 FP.
>
> But I wonder if usage of strictfp would change your results.
>
> Arne
[toc] | [prev] | [next] | [standalone]
| From | bursejan@gmail.com |
|---|---|
| Date | 2018-06-24 13:35 -0700 |
| Message-ID | <90082b6a-1547-4825-83f5-34f0762daad4@googlegroups.com> |
| In reply to | #38402 |
The test code would be:
for (int i=22; i<25; i++) {
System.out.println("Math.pow(10,"+i+")="+Math.pow(10,i));
}
The result (without strictfp modifier to main()) is:
Math.pow(10,22)=1.0E22
Math.pow(10,23)=1.0000000000000001E23
Math.pow(10,24)=1.0E24
The result (with strictfp modifier to main()) is:
Math.pow(10,22)=1.0E22
Math.pow(10,23)=1.0000000000000001E23
Math.pow(10,24)=1.0E24
Because invoking Math.pow() is not a basic operator +, *, /, etc..
Am Sonntag, 24. Juni 2018 22:31:44 UTC+2 schrieb burs...@gmail.com:
> You cannot use the strictfp keyword in front
> of Math.pow(). Thats only for the basic operations.
>
> Math.pow() itself is implemented in JDK 1.8 as follows:
>
> public static double pow(double a, double b) {
> return StrictMath.pow(a, b); // default impl. delegates to StrictMath
> }
>
> Am Sonntag, 24. Juni 2018 21:21:57 UTC+2 schrieb Arne Vajhøj:
> > On 6/24/2018 2:41 PM, j4n bur53 wrote:
> > > Running a simple test.
> > > ** is Math.pow(),
> > > ^ is BigInteger.pow() and then BigInteger.doubleValue().
> > >
> > > On Java:
> > >
> > > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
> > > 15-0.0
> >
> > > 23-1.6777216E7
> >
> > > 29-0.0
> > > 30-0.0
> > >
> > > On Adroid:
> > >
> > > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
> > > 15-0.0
> >
> > > 23-0.0
> >
> > > 29-1.7592186044416E13
> > > 30-0.0
> > >
> > > Has Android different floats?
> > > Tested jdk1.8.0_152 against Android 8.0.0
> >
> > ARM supposedly use standard IEEE 754 FP.
> >
> > But I wonder if usage of strictfp would change your results.
> >
> > Arne
[toc] | [prev] | [next] | [standalone]
| From | bursejan@gmail.com |
|---|---|
| Date | 2018-06-24 13:44 -0700 |
| Message-ID | <c9789a02-8696-4353-940a-bae36b9ed75f@googlegroups.com> |
| In reply to | #38403 |
You can try the same Java code on a Android
device. The result will be (Android 8.0.0):
Math.pow(10,22)=1.0E22
Math.pow(10,23)=9.999999999999999E22
Math.pow(10,24)=1.0E24
I used AIDE-IDE to compile and run the Java
directly on the device.
But the above is not the same test case as
in my initial post. My initial post also
tests BigInteger.pow() and BigInteger.doubleValue().
Am Sonntag, 24. Juni 2018 22:35:50 UTC+2 schrieb burs...@gmail.com:
> The test code would be:
>
> for (int i=22; i<25; i++) {
> System.out.println("Math.pow(10,"+i+")="+Math.pow(10,i));
> }
>
> The result (without strictfp modifier to main()) is:
>
> Math.pow(10,22)=1.0E22
> Math.pow(10,23)=1.0000000000000001E23
> Math.pow(10,24)=1.0E24
>
> The result (with strictfp modifier to main()) is:
>
> Math.pow(10,22)=1.0E22
> Math.pow(10,23)=1.0000000000000001E23
> Math.pow(10,24)=1.0E24
>
> Because invoking Math.pow() is not a basic operator +, *, /, etc..
>
> Am Sonntag, 24. Juni 2018 22:31:44 UTC+2 schrieb burs...@gmail.com:
> > You cannot use the strictfp keyword in front
> > of Math.pow(). Thats only for the basic operations.
> >
> > Math.pow() itself is implemented in JDK 1.8 as follows:
> >
> > public static double pow(double a, double b) {
> > return StrictMath.pow(a, b); // default impl. delegates to StrictMath
> > }
> >
> > Am Sonntag, 24. Juni 2018 21:21:57 UTC+2 schrieb Arne Vajhøj:
> > > On 6/24/2018 2:41 PM, j4n bur53 wrote:
> > > > Running a simple test.
> > > > ** is Math.pow(),
> > > > ^ is BigInteger.pow() and then BigInteger.doubleValue().
> > > >
> > > > On Java:
> > > >
> > > > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
> > > > 15-0.0
> > >
> > > > 23-1.6777216E7
> > >
> > > > 29-0.0
> > > > 30-0.0
> > > >
> > > > On Adroid:
> > > >
> > > > ?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
> > > > 15-0.0
> > >
> > > > 23-0.0
> > >
> > > > 29-1.7592186044416E13
> > > > 30-0.0
> > > >
> > > > Has Android different floats?
> > > > Tested jdk1.8.0_152 against Android 8.0.0
> > >
> > > ARM supposedly use standard IEEE 754 FP.
> > >
> > > But I wonder if usage of strictfp would change your results.
> > >
> > > Arne
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2018-06-24 17:28 -0400 |
| Message-ID | <pgp2es$ls9$1@dont-email.me> |
| In reply to | #38403 |
On 6/24/2018 4:35 PM, bursejan@gmail.com wrote:
> The test code would be:
>
> for (int i=22; i<25; i++) {
> System.out.println("Math.pow(10,"+i+")="+Math.pow(10,i));
> }
>
> The result (without strictfp modifier to main()) is:
>
> Math.pow(10,22)=1.0E22
> Math.pow(10,23)=1.0000000000000001E23
> Math.pow(10,24)=1.0E24
>
> The result (with strictfp modifier to main()) is:
>
> Math.pow(10,22)=1.0E22
> Math.pow(10,23)=1.0000000000000001E23
> Math.pow(10,24)=1.0E24
>
> Because invoking Math.pow() is not a basic operator +, *, /, etc..
Have you tried using StrictMath.pow() instead of Math.pow()?
It is certainly possible that the Math implementations are different
on different platforms -- at least, the Javadoc seems to allow such
freedom:
"[...] Code generators are encouraged to use platform-specific
native libraries or microprocessor instructions, where
available, to provide higher-performance implementations of Math
methods. [...]"
It's my understanding, though, that StrictMath implementations on all
platforms are supposed to agree exactly.
--
esosman@comcast-dot-net.invalid
Nine hundred forty-one days to go.
[toc] | [prev] | [next] | [standalone]
| From | bursejan@gmail.com |
|---|---|
| Date | 2018-06-24 16:08 -0700 |
| Message-ID | <7bf8cf29-d6fc-4e18-b31a-81d9a8d66ba6@googlegroups.com> |
| In reply to | #38405 |
Yes, this seems to be the explanation, on the
windows platform, Math.pow() seems to get replaced
by something else than StrictMath.pow().
With StrictMath.pow() (JDK 1.8, Windows):
Math.pow(10,22)=1.0E22
Math.pow(10,23)=9.999999999999999E22
Math.pow(10,24)=1.0E24
With Math.pow() (JDK 1.8, Windows):
Math.pow(10,22)=1.0E22
Math.pow(10,23)=1.0000000000000001E23
Math.pow(10,24)=1.0E24
What is Math.pow() doing on Windows, some Wintel nonsense?
Am Sonntag, 24. Juni 2018 23:29:11 UTC+2 schrieb Eric Sosman:
> On 6/24/2018 4:35 PM, bursejan@gmail.com wrote:
> > The test code would be:
> >
> > for (int i=22; i<25; i++) {
> > System.out.println("Math.pow(10,"+i+")="+Math.pow(10,i));
> > }
> >
> > The result (without strictfp modifier to main()) is:
> >
> > Math.pow(10,22)=1.0E22
> > Math.pow(10,23)=1.0000000000000001E23
> > Math.pow(10,24)=1.0E24
> >
> > The result (with strictfp modifier to main()) is:
> >
> > Math.pow(10,22)=1.0E22
> > Math.pow(10,23)=1.0000000000000001E23
> > Math.pow(10,24)=1.0E24
> >
> > Because invoking Math.pow() is not a basic operator +, *, /, etc..
>
> Have you tried using StrictMath.pow() instead of Math.pow()?
> It is certainly possible that the Math implementations are different
> on different platforms -- at least, the Javadoc seems to allow such
> freedom:
>
> "[...] Code generators are encouraged to use platform-specific
> native libraries or microprocessor instructions, where
> available, to provide higher-performance implementations of Math
> methods. [...]"
>
> It's my understanding, though, that StrictMath implementations on all
> platforms are supposed to agree exactly.
>
> --
> esosman@comcast-dot-net.invalid
> Nine hundred forty-one days to go.
[toc] | [prev] | [next] | [standalone]
| From | bursejan@gmail.com |
|---|---|
| Date | 2018-06-26 10:29 -0700 |
| Message-ID | <eecccf4c-862b-4a1b-9777-6c39fa357538@googlegroups.com> |
| In reply to | #38406 |
I didn't send or was involved in the last 7 emails. Maybe some robot was going astray. LoL
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web