Rudimentary C99 Hexadecimal Floating Point Support in Perl6
Perl6
Switch branches/tags
Nothing to show
Latest commit 7239552 Jan 8, 2016 Dan Kogai update t/00-basic.t
Permalink
Failed to load latest commit information.
lib/Num handle [+-](0.0|inf) Jan 8, 2016
t update t/00-basic.t Jan 8, 2016
.gitignore Initial commit Jan 4, 2016
.travis.yml add .travis.yml Jan 4, 2016
LICENSE Initial commit Jan 4, 2016
META.info version 0.1.2 Jan 8, 2016
README.md Update README.md Jan 4, 2016

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.