Skip to content
New issue

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

C library: additional floating-point functions and cleanup #8195

Merged
merged 9 commits into from
Feb 8, 2024

Conversation

tautschnig
Copy link
Collaborator

Please see individual commit messages.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link

codecov bot commented Feb 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c81a6a6) 79.66% compared to head (c56f167) 79.66%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8195   +/-   ##
========================================
  Coverage    79.66%   79.66%           
========================================
  Files         1682     1682           
  Lines       195377   195377           
========================================
  Hits        155641   155641           
  Misses       39736    39736           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -854,11 +899,14 @@ float sqrtf(float f)
// number of exponent and significand bits. Thus they are
// given implicitly...

#pragma CPROVER check push
#pragma CPROVER check disable "float-overflow"
float lowerSquare = lower * lower;
__CPROVER_assume(__CPROVER_isnormalf(lowerSquare));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A square root may well be denormal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's possible for the case that f (which we are taking the square root of) is normal, which this branch assumes: given a denormal number is smaller than 1, any denormal square root s cannot be smaller than f (for $s < 1 \wedge s \geq 0 \implies s^2 \leq s$), so f has to be denormal when s is denormal.

Follows the same approximation approach as previously taken for log (and
logf, logl).
We previously ended up with recursion.
Model floating-point exceptions as failing assertions.
Model fused multiply-add as documented in its man page.
We construct NaN (and Inf) by dividing by zero, which is a
standards-compliant way in that Nan (Inf) is the correct result for
these cases. Do not flag these operations as division-by-zero, which the
user would not expect.
Fail as documented rather than via built-in assertions when overflowing.
We guess upper and lower bounds and check them for infinity afterwards.
Those multiplications should not be flagged by auto-generated
assertions.
Visual Studio knows static_assert, but not the standardised
_Static_assert.
Visual Studio uses `1.000000e+300 * 1.000000e+300` as value behind the
`HUGE_VAL` macro. We should not report an overflow for this approach of
producing infinity.
@tautschnig tautschnig merged commit 9c7bccc into diffblue:develop Feb 8, 2024
39 checks passed
@tautschnig tautschnig deleted the bugfixes/math-lib branch February 8, 2024 16:19
tautschnig added a commit to model-checking/kani that referenced this pull request Aug 2, 2024
github-merge-queue bot pushed a commit to model-checking/kani that referenced this pull request Aug 2, 2024
Implemented in CBMC in diffblue/cbmc#8195.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.

Co-authored-by: Felipe R. Monteiro <felisous@amazon.com>
github-merge-queue bot pushed a commit to model-checking/kani that referenced this pull request Aug 2, 2024
CBMC's sqrt* implementations were fixed in
diffblue/cbmc#8195.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
tautschnig added a commit to model-checking/kani that referenced this pull request Aug 2, 2024
tautschnig added a commit to model-checking/kani that referenced this pull request Aug 2, 2024
CBMC's sqrt* implementations were fixed in diffblue/cbmc#8195.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Front End Kani Bugs or features of importance to Kani Rust Verifier
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants