develooper Front page | perl.perl5.porters | Postings from October 2018

[perl #133582] POSIX::log2 weird behaviour

Thread Previous
From:
sisyphus@cpan.org via RT
Date:
October 26, 2018 00:37
Subject:
[perl #133582] POSIX::log2 weird behaviour
Message ID:
rt-4.0.24-11546-1540514243-1940.133582-15-0@perl.org
On Tue, 16 Oct 2018 17:12:33 -0700, sisyphus@cpan.org wrote:
> On Tue, 16 Oct 2018 09:04:25 -0700, me@xenu.pl wrote:
> > Or maybe use this[1] list, it seems to be pretty comprehensive.
> >
> > [1] -
> > https://blogs.msdn.microsoft.com/b/vcblog/archive/2013/07/19/c99-
> > library-support-in-visual-studio-2013.aspx
> 
> I had a look through mingw's math.h (gcc-4.4.3) to see what was there.
> I then looked through the 2 '.gc' files, and found that they
> disallowed the use of the following available functions:
> 
> cbrt
> acosh
> asinh
> atanh
> copysign
> copysignl
> erf
> exp2
> expm1
> finite
> fmax
> fmin
> fpclass
> fpclassify
> hypot
> ilogb
> ilogbl
> isinf
> isless
> isnanl
> isnormal
> j0
> lgamma
> llrint
> llrintl
> llround
> llroundl
> log1p
> log2
> logb
> lrint
> lrintl
> lround
> lroundl
> nan
> nearbyint
> nextafter
> nexttoward
> remainder
> remquo
> rint
> round
> scalbn
> scalbnl
> signbit
> sqrtl
> tgamma
> trunc
> truncl
> 
> Interestingly, there's an "#ifdef WIN32" block in POSIX.xs that then
> allows the gcc and msvc implementations of hypot, logb, nextafter, j0,
> j1, jn, y0, y1, and yn.
> 
> 
> The math.t test script would also need some attention as it
> unconditionally avoids testing the C99 Math functions on Windows.
> 
> I'll enable all of those "disabled" functions in the '.gc' files, do
> some testing and present some patches.
> 
> However, I've no interest in doing anything as regards the '.vc'
> files.
> 
> Cheers,
> Rob

With the attached patches to blead, the following keys are now defined in %Config when perl is built with a mingw-w64 port of gcc.

d_cbrt
d_acosh d_asinh d_atanh
d_copysign d_copysignl
d_erf
d_exp2 d_expm1
d_finite d_nan
d_fmax d_fmin
d_frexpl
d_hypot
d_ilogb d_ilogbl d_log1p d_log2 d_logb
d_isinf
d_isless d_isnanl d_isnormal
d_j0
d_lgamma d_tgamma
d_rint d_lrint d_lrintl d_llrint d_llrintl
d_round d_lround d_lroundl d_llround d_llroundl
d_modfl
d_nearbyint d_nextafter d_nexttoward
d_remainder d_remquo
d_scalbn d_scalbnl
d_signbit
d_sqrtl
d_trunc d_truncl

Those settings then match those for perls built using gcc on Ubuntu-18.04 - with one exception.
On Ubuntu $Config{d_isless} is set to 'undef'.

I would have liked to include d_fpclassify in the above list, but fpclassify() is buggy on 32-bit mingw-w64 compilers wrt doubles.
Using gcc-8.1.0 and the latest mingw runtime, incorrect results occur when optimization is enabled - which, of course, is the normal case with perl.
With at least some earlier compilers/runtimes, the bug exists even when optimization is turned off.
See https://sourceforge.net/p/mingw-w64/bugs/367/.
Defining 'd_fpclassify' thereby causes sv.c's hextract() sub to produce incorrect "%a" formatting of subnormal doubles.
Anyway, perl's current implementation of the fpclassify() functionality seems fine - so I'll leave 'd_fpclassify' as undef.

Defining 'd_modfl' is a little dubious. Although it's been fixed in the latest runtime, modfl is buggy in some earlier runtimes (including the one that Strawberry Perl currently uses).
However, 'd_modfl' has been defined in 'long double' builds of Windows perl since they were first made possible and the workarounds needed are already in place and working fine.
So, given that modfl has now been fixed, I decided to leave 'd_modfl' as defined.

I have however, moved the defining of 'd_modfl' (along with 'd_frexpl', d_isnanl' and 'd_sqrtl) from config_sh.PL to config.gc/config_H.gc.
I did this to match the handling of all of the other C99 math functions.

These patches aim to make changes only WRT mingw builds of perl, whilst altering nothing WRT perls built using a Microsoft compiler.

The following configurations, using mingw-w64 ports of gcc-8.1.0 test fine:

1) 32 bit, ivsize=8, nvtype=double, __USE_MINGW_ANSI_STDIO defined
2) 64 bit, ivsize=8, nvtype=double, __USE_MINGW_ANSI_STDIO defined

3) 32 bit, ivsize=8, nvtype=double, __USE_MINGW_ANSI_STDIO not defined
4) 64 bit, ivsize=8, nvtype=double, __USE_MINGW_ANSI_STDIO not defined

5) 32 bit, ivsize=4, nvtype=double, __USE_MINGW_ANSI_STDIO defined
6) 64 bit, ivsize=4, nvtype=double, __USE_MINGW_ANSI_STDIO defined

7) 32 bit, ivsize=8, nvtype=longdouble, __USE_MINGW_ANSI_STDIO defined
8) 64 bit, ivsize=8, nvtype=longdouble, __USE_MINGW_ANSI_STDIO defined

Cheers,
Rob

 



---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=133582

Thread Previous


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