tags:

views:

47

answers:

2

Most of the perl installations I use have uselongdouble undefined, but d_longdbl defined. Literally I guess this means that long doubles are not used as the default floating point type, but long doubles are 'supported'. I'm confused though about what it means for long doubles to be 'supported'. As far as I know, Perl doesn't have any mechanism for casting or promoting to the higher precision from the default. How would you get a long double into a Perl program if the default floating point type is a vanilla double.

A: 

You can check the support for long doubles at runtime with the Config module. Here is sample code from perldoc that shows the use:

  use Config;
    if ($Config{uselongdouble} eq "define") {
    print "long doubles by default\n";
    }

This example is from the section on sprintf (which I just happened to be reading...) and there are other examples there.

With respect to casting or promoting, I do not think you can. Perl uses its longest double for all math, including integer math. (unless you invoke the pragma use integer)

drewk
Thanks, but what I'm looking for is why there are two distinct configuration parameters, uselongdouble, and d_longdbl, and in particluar what it means to have one defined and the other not defined. In fact the meaning of uselongdouble is pretty clear. It's d_longdbl that seems more mysterious.
Charles E. Grant
Looking at the Perl config script, I believe that `d_longdbl` is defined if the build system is *capable* of doing long doubles and is determined by the script; *uselongdouble* is defined if the arguments to the Perl config script mean that you *want* a long double build. ie, the later is a dependent of the former, but you can only select to build a long double version only if `d_longdbl` is defined by the script detecting long double capability.
drewk
+2  A: 

d_longdbl just says that there is support for long doubles in the environment that built perl.

This results in the C macro HAS_LONG_DOUBLE being set, which is a prerequisite for USE_LONG_DOUBLE and enables the L and ll s/printf modifiers.

(It is also available to XS modules, which are free to change behavior based on it.)

ysth
It would be nice if this also allowed pack and unpack of long doubles (even though there'd be less precision on the perl side without uselongdouble).
ysth