<commit_before>use v6;
unit module Num::HexFloat;
our $RE_HEXFLOAT is export = rx:i{
    $<sign>  = [<[+-]>?]
    0x
    $<int>   = [<[0..9A..F]>+]
    '.'?
    $<fract> = [<[0..9A..F]>*]
    'P'
    $<exp>   = [<[+-]>? <[0..9]>+]
};
# should've been multi but it didn't work :(
proto from-hexfloat($arg) returns Num is export { * }
multi sub from-hexfloat(Match $m) returns Num {
    return NaN unless $m;
    my $sign = $m<sign> eq '-' ?? -1e0 !! 1e0;
    my $mantissa = :16( $m<int> ~ $m<fract> );
    my $exponent = $m<exp>.Num - 4*$m<fract>.chars;
    return $sign * $mantissa * 2e0 ** $exponent;
}
multi sub from-hexfloat(Str $s) returns Num {
    from-hexfloat($s.match($RE_HEXFLOAT));
}
proto sub to-hexfloat($num) returns Str is export { * }
multi sub to-hexfloat($num) returns Str {<commit_msg>update comment<commit_after>use v6;
unit module Num::HexFloat;
our $RE_HEXFLOAT is export = rx:i{
    $<sign>  = [<[+-]>?]
    0x
    $<int>   = [<[0..9A..F]>+]
    '.'?
    $<fract> = [<[0..9A..F]>*]
    'P'
    $<exp>   = [<[+-]>? <[0..9]>+]
};
proto from-hexfloat($arg) returns Num is export { * }
multi sub from-hexfloat(Match $m) returns Num {
    return NaN unless $m;
    my $sign = $m<sign> eq '-' ?? -1e0 !! 1e0;
    my $mantissa = :16( $m<int> ~ $m<fract> );
    my $exponent = $m<exp>.Num - 4*$m<fract>.chars;
    return $sign * $mantissa * 2e0 ** $exponent;
}
multi sub from-hexfloat(Str $s) returns Num {
    from-hexfloat($s.match($RE_HEXFLOAT));
}
proto sub to-hexfloat($num) returns Str is export { * }
multi sub to-hexfloat($num) returns Str {
{'fraction_non_alphanumeric': 0.2231457800511509, 'fraction_numerical': 0.021739130434782608, 'mean_word_length': 3.064935064935065, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6917019', 'n_tokens_mistral': 681, 'n_tokens_neox': 649, 'n_words': 156}