develooper Front page | perl.perl5.porters | Postings from June 2021

Re: quadmath with 32 bit ints

Thread Previous | Thread Next
From:
sisyphus
Date:
June 12, 2021 12:44
Subject:
Re: quadmath with 32 bit ints
Message ID:
CADZSBj1AQBPf3ywJKRYWfD=tuhc_ceMmWOrD8Ky7Y4bNUP+jYw@mail.gmail.com
On Fri, Jun 11, 2021 at 4:46 PM Peter John Acklam <pjacklam@gmail.com>
wrote:

I got something working. It stops with $e = 16 and $use_int = 0. Even
> with $e = 17, all the values are within the range of what can be
> represented exactly with 128 bit floats, but certain things fail. For
> instance, I expected the following to return 1
>
> $ perl -wle 'print( (2**113 - 1) % 2)'
> 0
>
> I guess it has to do with how the % operator is implemented. I haven't
> dug into it. POSIX::fmod() gets it right, though
>
> $ perl -MPOSIX -wle 'print fmod(2**113 - 1, 2)'
> 1
>
> but I don't think it's worth requiring the POSIX module just to get $e
> = 17 rather than $e = 16.
>

I notice that a comparable anomaly arises when ivsize == 4 and nvtype is
the 64-bit precision long double (nvsize == 12).:

C:\>perl -le "print ( (2**64 - 1) % 2);"
0

C:\>perl -MPOSIX -le "print fmod(2**64 - 1, 2);"
1

Yet, for this configuration, there's no problem with the existing Calc.pm
code.

Why is it that the problem arises only when ivsize == 4 && nvsize == 16 ?

Cheers,
Rob

PS  Based on the above I expected that, on a perl whose ivsize == 4 &&
nvsize == 8, the expression '"print ((2** 53 - 1) % 2);' would also output
0 ... but it doesn't:

C:\>perl -MConfig -le "print $Config{ivsize}; print $Config{nvsize}; print
( (2**53 - 1) % 2);"
4
8
1

This is not making sense to me.
If a perl whose ivsize == 4 && nvsize == 8 determines that  (2**53 - 1) % 2
== 1 then, by extrapolation:
1)  a perl whose ivsize == 4 && nvsize == 12 should determine that  (2** 64
- 1) % 2 == 1
&&
2) a perl whose ivsize == 4 && nvsize == 16 should determine that  (2** 113
- 1) % 2 == 1

But points 1) and 2) are not being met.
Am I missing something ?

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About