Ancient

 view release on metacpan or  search on metacpan

t/lib/TestVec.pm  view on Meta::CPAN


=over 4

=item B<relative> (default)

Compares using relative error scaled by machine epsilon. Best for general use
as it handles values of different magnitudes correctly.

=item B<ulp>

Counts "Units in Last Place" - the number of representable floats between
two values. Most mathematically rigorous for numerical algorithm testing.

=item B<exact>

Compares the actual bit representation. Use when values should be identical.

=item B<absolute>

Traditional absolute tolerance. Use with caution as it doesn't scale with
value magnitude.

=back

=head2 NV Type Detection

    is_quadmath()      # True if using __float128 (34 digits)
    is_long_double()   # True if using long double (21 digits typically)
    nv_info()          # Hash with all NV details
    nv_epsilon()       # Actual machine epsilon
    nv_digits()        # Decimal digits of precision

=head1 FUNCTIONS

=head2 float_is($got, $expected, $name, \%opts)

Primary test function. Options:

    method    => 'relative'|'ulp'|'exact'|'absolute'
    ulps      => N        # Max ULPs for relative/ulp methods (default: 4)
    tolerance => N        # Absolute tolerance for absolute method

=head2 float_ok($got, $expected, $name, $ulps)

Shorthand for float_is with relative comparison.

=head2 relatively_equal($a, $b, $ulps)

Returns true if values are within $ulps relative ULPs.

=head2 ulp_distance($a, $b)

Returns the ULP distance between two values (-1 on error).

=head2 bits_equal($a, $b)

Returns true if values have identical bit representation.

=head2 bits_hex($val)

Returns hex string of value's bit representation (for debugging).

=head1 QUADMATH TESTING

To test with quadmath:

    docker run --rm -v $(pwd):/work -w /work perl:5.40-threaded \
        perl -Mblib t/your_test.t

The module auto-detects the NV type and adjusts tolerances accordingly.

=cut



( run in 0.375 second using v1.01-cache-2.11-cpan-5511b514fd6 )