Rudimentary C99 Hexadecimal Floating Point Support in Perl6
Other
Switch branches/tags
Nothing to show
Latest commit 4156f40 Apr 29, 2017 Dan Kogai fix to-hexfloat(-0e0)
Permalink
Failed to load latest commit information.
lib/Num
t
.gitignore
.travis.yml
LICENSE
META6.json
README.md

README.md

build status

NAME

Num::HexFloat - Rudimentary C99 Hexadecimal Floating Point Support in Perl6

SYNOPSIS

use v6;
use Num::HexFloat;
   
say to-hexfloat(pi);
# '0x1.921fb54442d18p+1'
say from-hexfloat('0x1.921fb54442d18p+1') == pi;
# True
my $src = "e=0x1.5bf0a8b145769p+1, pi=0x1.921fb54442d18p+1";
say $src.subst($RE_HEXFLOAT, &from-hexfloat, :g);
# e=2.71828182845905, pi=3.14159265358979

DESCRIPTION

Num::HexFloat exports the following:

$RE_HEXFLOAT

A regex that matches hexadecimal floating point notation.

from-hexfloat($arg) returns Num

Parses $arg as a C99 hexadecimal floating point notation and returns Num, or NaN if it fails.

$arg can be either Str or Match so you can go like:

$src.subst($RE_HEXFLOAT, &from-hexfloat, :g);

to-hexfloat(Numeric $num) returns Str

Stringifies $num in C99 hexadecimal floating point notation.