We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It would be nice if testworks provide at least one method to compare floating-point numbers
The text was updated successfully, but these errors were encountered:
I need this as well now.
Previously, @niko2342 had found https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ which seems like a good start.
Sorry, something went wrong.
To compare ULPs, you can use decode-single-float or decode-double-float from dylan-extensions:
decode-single-float
decode-double-float
dylan-extensions
let desired-lo = decode-double-float(desired); let calc-lo = decode-double-float(calc); assert-true(abs(as(<integer>, desired-lo) - as(<integer>, calc-lo)) < 2)
@housel pointed me at this code from Gwydion Dylan:
define constant $max-ulps = 3.0d0; define method almost-equal (x :: <float>, y :: <real>) => (result :: <boolean>) if (y.zero?) abs(x) < scale-float($max-ulps, 1 - float-digits(x)); else let (x-sig, x-exp, x-sign) = decode-float(x); let scaled-diff = abs(scale-float(x, - x-exp) - scale-float(y, - x-exp)); let ulp-diff = scale-float(scaled-diff, float-digits(x) - 1); ulp-diff < $max-ulps; end if; end method almost-equal;
No branches or pull requests
It would be nice if testworks provide at least one method to compare floating-point numbers
The text was updated successfully, but these errors were encountered: