syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I was expecting that, on -Dusequadmath builds of perl, the POSIX module would provide me with the value of FLT128_MAX (== 1.18973149535723176508575932662800702e4932, as defined in quadmath.h).
But it doesn't:
$ perl -MPOSIX -wle 'print POSIX::FLT128_MAX;' Name "POSIX::FLT128_MAX" used only once: possible typo at -e line 1. print() on unopened filehandle FLT128_MAX at -e line 1.
Is this simply a case of "bad expectation" on my part ?

Cheers,
Rob

Replies are listed 'Best First'.
Re: POSIX and -Dusequadmath
by afoken (Chancellor) on Sep 09, 2017 at 07:14 UTC

    I've looked at several POSIX documents (limits.h, math.h, float.h). It seems that POSIX knows only float, double, and long double. According to Wikipedia, long double may be a 128 bit float - but unfortunately, that depends on the implementation. On x86, it is commonly the 80 bit float format of the 80x87. HP-UX and Solaris/SPARC actually use the name long double for 128 bit floats. And compilers may choose to treat long double as an alias for double, like MS VC++ does.

    It looks like quadmath.h is no POSIX standard header. So strictly speaking, the FLT128_XXX definitons don't belong into the POSIX module.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      the FLT128_XXX definitons don't belong into the POSIX module

      Yeah ... I had a vague notion that those definitions might be outside of POSIX's "terms of reference".

      That being so, what is the best way to assign the FLT128_MAX value to a scalar on a -Dusequadmath perl (and without calling on a non-CORE module) ?
      I really can't think of any better way than doing $nv_max = 1.18973149535723176508575932662800702e4932;
      But that string of numbers is not quite as easy to remember as "POSIX::FLT128_MAX".
      A little easier to remember is $nv_max = 0x1.ffffffffffffffffffffffffffffp+16383 except that it provides the wrong result on perl-5.22.0 (the first stable release of perl to support -Dusequadmath):
      $ perl -le '$x = 0x1.ffffffffffffffffffffffffffffp+16383; print $x;' Inf
      Just lately I seem to often want to assign NV_MAX to a perl scalar (for various exercises regarding some testing of code).
      For nvtype='double' I can use POSIX::DBL_MAX and for nvtype='long double' I can use POSIX::LDBL_MAX. It would therefore be nice to be able to use POSIX::FLT128_MAX when nvtype='__float128'.
      But if that can't be then it's really not such a big deal to use other means, though it is a bit of a nuisance having to continually look up the value.

      Cheers,
      Rob
        You can consider building a private module to define "seldom used" constants such as this. I would include "user" constants such as your local longitude and latitude, and characteristics of your hardware.
        Bill

        Nothing in use Config to help you?

        As an aside, if you fancy a laugh, enter that constant into Wolfram Alpha and see what happens :)


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
        In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
Re: POSIX and -Dusequadmath
by Anonymous Monk on Sep 08, 2017 at 23:07 UTC