- NAME
- BUGS
- DESCRIPTION
- OVERLOADING
- ASSIGNMENT FUNCTIONS
- ASSIGNMENT OF INF, NAN, UNITY and ZERO
- RETRIEVAL FUNCTIONS
- OTHER FUNCTIONS
- BUGS
- LICENSE
- AUTHOR

# NAME

Math::Float128 - perl interface to C's __float128 operations

# BUGS

```
1) exp() segfaults with Strawberry Perl's 32-bit and 64-bit MinGW
compilers.
2) Needs quadmath.h in order to build.
```

# DESCRIPTION

```
use Math::Float128 qw(:all);
my $arg = 32.1;
my $f1 = Math::Float128->new($arg);# Stringify $arg, then assign
# using C's strtoflt128()
my $f2 = NVtoF128($arg); # Assign the NV 32.1 to $f2.
```

# OVERLOADING

```
The following operations are overloaded:
+ - * / **
+= -= *= /= **=
!= == <= >= <=> < >
++ --
=
abs bool ! int print
sqrt log exp
sin cos atan2
Arguments to the overloaded operations must be Math::Float128
objects.
$f = $f + 3.1; # currently an error. Do instead:
$f = $f + Math::Float128->new('3.1');
```

# ASSIGNMENT FUNCTIONS

```
The following create and assign a new Math::Float128.
$f = Math::Float128->new($arg);
Returns a Math::Float128 object to which the numeric value of $arg
has been assigned.
If no arg is supplied then $f will be NaN.
$f = UVtoF128($arg);
Returns a Math::Float128 object to which the numeric (unsigned
integer) value of $arg has been assigned.
$f = IVtoF128($arg);
Returns a Math::Float128 object to which the numeric (signed
integer) value of $arg has been assigned.
$f = NVtoF128($arg);
Returns a Math::Float128 object to which the numeric (floating
point) value of $arg has been assigned.
$f2 = F128toF128($f1);
Returns a Math::Float128 object that is a copy of the
Math::Float128 object provided as the argument.
Courtesy of overloading, this is in effect no different to doing:
$f2 = $f1;
$f = STRtoF128($str);
Returns a Math::Float128 object that has the value of the string
$str.
```

# ASSIGNMENT OF INF, NAN, UNITY and ZERO

```
$f = InfF128($sign);
If $sign < 0, returns a Math::Float128 object set to
negative infinity; else returns a Math::Float128 object set
to positive infinity.
$f = NaNF128($sign);
If $sign < 0, returns a Math::Float128 object set to
negative NaN; else returns a Math::Float128 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.
$f = ZeroF128($sign);
If $sign < 0, returns a Math::Float128 object set to
negative zero; else returns a Math::Float128 object set to
zero.
$f = UnityF128($sign);
If $sign < 0, returns a Math::Float128 object set to
negative one; else returns a Math::Float128 object set to
one.
flt128_set_prec($precision);
Sets the precision of stringified values to $precision decimal
digits.
$precision = flt128_get_prec();
Returns the precision (in decimal digits) that will be used
when stringifying values (by printing them, or calling
F128toSTR).
```

# RETRIEVAL FUNCTIONS

```
The following functions provide ways of seeing the value of
Math::Float128 objects.
$nv = F128toNV($f);
This function returns the value of the Math::Float128 object to
a perl scalar (NV). It may not translate the value accurately.
$string = F128toSTR($f);
Returns the value of the Math::Float128 object as a string.
The returned string will contain the same as is displayed by
"print $f", except that print() will strip the trailing zeroes
in the mantissa (significand) whereas F128toSTR won't.
By default, provides 33 decimal digits of precision. This can be
altered by specifying the desired precision (in decimal digits)
in a call to flt128_set_prec.
$string = F128toSTRP(f, $precision);
Same as F128toSTR, but takes an additional arg that specifies the
precision (in decimal digits) of the stringified return value.
```

# OTHER FUNCTIONS

```
$bool = is_NaNF128($f);
Returns 1 if $f is a Math::Float128 NaN.
Else returns 0
$int = is_InfF128($f)
If the Math::Float128 object $f is -inf, returns -1.
If it is +inf, returns 1.
Otherwise returns 0.
$int = is_ZeroF128($f);
If the Math::Float128 object $f is -0, returns -1.
If it is zero, returns 1.
Otherwise returns 0.
$int = cmp2NV($f, $nv);
$nv can be any perl number - ie NV, UV or IV.
If the Math::Float128 object $f < $nv returns -1.
If it is > $nv, returns 1.
Otherwise returns 0.
```

# BUGS

```
The mingw64 compilers have a buggy expq() function; therefore the
overloaded exp function doesn't return expq($arg) when a mingw64
compiler is in use - instead it returns e**$arg.
```

# LICENSE

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

# AUTHOR

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