The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::LongDouble - perl interface to C's long double operations (for perls that don't already have that capability)

BUGS

  This module has bugs on perls built with a Microsoft compiler (eg
  ActivePerl) - even if the binaries installed onto the MSVC-built
  perl were built using MinGW on a MinGW-built perl such as Strawberry
  Perl (where no such problem exists).
  By some means that is still unclear, the 'long double' precision
  can apparently be reduced to 'double' precision whenever a 
  Math::LongDouble object is raised to a power (or a square root taken)
  on MSVC-built perls.
  This bug manifests itself in causing some test failures in t/cmp.t
  and t/pow.t.

DESCRIPTION

  If your perl's NV is a 'long double', then there's no point in using this
  module. But if your perl's NV is a 'double', then this module provides
  you with a way of performing arithmetic operations with long double
  precision.

   use Math::LongDouble qw(:all);

   my $arg = 32.1;
   my $ld1 = Math::LongDouble->new($arg);# Stringify $arg, then assign 
                                          # using C's strtold()
   my $ld2 = NVtoLD($arg); # Assign the NV 32.1 to $ld2.

OVERLOADING

   The following operations are overloaded:
    + - * / **
    += -= *= /= **=
    != == <= >= <=> < >
    ++ --
    =
    abs bool ! int print
    sqrt log exp
    sin cos atan2

    Arguments to the overloaded operations must be Math::LongDouble
    objects.

     $ld = $ld + 3.1; # currently an error. Do instead:

     $ld = $ld + Math::LongDouble->new('3.1');

ASSIGNMENT FUNCTIONS

   The following create and assign a new Math::LongDouble.

    $ld = Math::LongDouble->new($arg);
     Returns a Math::LongDouble object to which the numeric value of $arg
     has been assigned.
     If $arg is Math::LongDouble object, then it creates a copy of that
     object. Else, it first stringifies $arg, then assigns that numeric
     value using C's strtold function.

    $ld = UVtoLD($arg);
     Returns a Math::LongDouble object to which the numeric (unsigned
     integer) value of $arg has been assigned.

    $ld = IVtoLD($arg);
     Returns a Math::LongDouble object to which the numeric (signed
     integer) value of $arg has been assigned.

    $ld = NVtoLD($arg);
     Returns a Math::LongDouble object to which the numeric (floating
     point) value of $arg has been assigned.

    $ld = LDtoLD($arg);
     Returns a Math::LongDouble object to which the numeric (floating
     point) value of $arg has been assigned.

    $ld2 = STRtoLD($ld);
     Returns a Math::LongDouble object that is a copy of the
     Math::LongDouble object provided as the argument.

ASSIGNMENT OF INF, NAN and ZERO

   $ld = InfLD($sign);
    If $sign < 0, returns a Math::LongDouble object set to
    negative infinity; else returns a Math::Decimal64 object set
    to positive infinity.

   $ld = NaNLD($sign);
    If $sign < 0, returns a Math::longDouble object set to
    negative NaN; else returns a Math::LongDouble object set to
    positive NaN. It may be problematical as to whether a NaN
    with the correct sign has been returned ... but, either way,
    it should return a NaN.

   $ld = ZeroLD($sign);
    If $sign < 0, returns a Math::LongDouble object set to
    negative zero; else returns a Math::LongDouble object set to 
    zero.

RETRIEVAL FUNCTIONS

   The following functions provide ways of seeing the value of
   Math::LongDouble objects.

   $nv = LDtoNV($ld);
    This function returns the value of the Math::LongDouble object to
    a perl scalar (NV). It may not translate the value accurately.

   $string = LDtoSTR($ld);
    Returns the value of the Math::LongDouble object as a string.
    The returned string will contain the same as is displayed by
    "print $ld", except that print() will strip the trailing zeroes
    in the mantissa (significand) whereas LDtoSTR won't.

OTHER FUNCTIONS

   $bool = is_NaNLD($ld); 
    Returns 1 if $ld is a Math::LongDouble NaN.
    Else returns 0

   $int = is_InfLD($ld)
    If the Math::LongDouble object $ld is -inf, returns -1.
    If it is +inf, returns 1.
    Otherwise returns 0.

   $int = is_ZeroLD($ld);
    If the Math::LongDouble object $ld is -0, returns -1.
    If it is zero, returns 1.
    Otherwise returns 0.

   $int = cmp_NV($ld, $nv);
    If the Math::LongDouble object $ld < $nv returns -1.
    If it is > $nv, returns 1.
    Otherwise returns 0.
     

LICENSE

   This program is free software; you may redistribute it and/or modify
   it under the same terms as Perl itself.
   Copyright 2012 Sisyphus

AUTHOR

   Sisyphus <sisyphus at(@) cpan dot (.) org>