Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/kani/Intrinsics/Math/fabsf32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Check that `fabsf32` returns the expected results: absolute value if argument
// is not NaN, otherwise NaN
#![feature(core_intrinsics)]

#[kani::proof]
fn test_abs_finite() {
let x: f32 = kani::any();
kani::assume(!x.is_nan());
let abs_x = unsafe { std::intrinsics::fabsf32(x) };
if x < 0.0 {
assert!(-x == abs_x);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

At first I was surprised that this was == and not diff < epsilon but I see that floating point has an explicit sign bit https://en.wikipedia.org/wiki/Floating-point_arithmetic#IEEE_754:_floating_point_in_modern_computers

} else {
assert!(x == abs_x);
}
}

#[kani::proof]
fn test_abs_nan() {
let x: f32 = kani::any();
kani::assume(x.is_nan());
let abs_x = unsafe { std::intrinsics::fabsf32(x) };
assert!(abs_x.is_nan());
}
26 changes: 26 additions & 0 deletions tests/kani/Intrinsics/Math/fabsf64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Check that `fabsf64` returns the expected results: absolute value if argument
// is not NaN, otherwise NaN
#![feature(core_intrinsics)]

#[kani::proof]
fn test_abs_finite() {
let x: f64 = kani::any();
kani::assume(!x.is_nan());
let abs_x = unsafe { std::intrinsics::fabsf64(x) };
if x < 0.0 {
assert!(-x == abs_x);
} else {
assert!(x == abs_x);
}
}

#[kani::proof]
fn test_abs_nan() {
let x: f64 = kani::any();
kani::assume(x.is_nan());
let abs_x = unsafe { std::intrinsics::fabsf64(x) };
assert!(abs_x.is_nan());
}