Rand Stats

The uploading author of github:dankogai does not match the META author of zef:dankogai.

Num::HexFloat

github:dankogai

.github/workflows/test.yml

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.