What does it mean to have uselongdouble undefined, but d_longdbl defined in the Perl build configuration?
Most of the perl installations I use have uselongdouble undefined, but d_longdbl defined. Literally I开发者_JAVA百科 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.
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.)
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
)
精彩评论