File tree 4 files changed +116
-0
lines changed
tests/kani/Intrinsics/Math/Trigonometry
4 files changed +116
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ // Check that `cosf32` returns the expected results.
5
+ // Note: The CBMC model for this function is an over-approximation that returns:
6
+ // * A nondet. value between -1 and 1
7
+ // * 1.0 if the argument is 0.0
8
+ #![ feature( core_intrinsics) ]
9
+
10
+ fn fp_equals ( value : f32 , expected : f32 ) -> bool {
11
+ let abs_diff = ( value - expected) . abs ( ) ;
12
+ abs_diff <= f32:: EPSILON
13
+ }
14
+
15
+ #[ kani:: proof]
16
+ fn cosine_range ( ) {
17
+ let x: f32 = kani:: any ( ) ;
18
+ kani:: assume ( x. is_finite ( ) ) ;
19
+ let cosine = unsafe { std:: intrinsics:: cosf32 ( x) } ;
20
+ assert ! ( cosine < 1.0 || fp_equals( cosine, 1.0 ) ) ;
21
+ assert ! ( cosine > -1.0 || fp_equals( cosine, -1.0 ) ) ;
22
+ }
23
+
24
+ #[ kani:: proof]
25
+ fn cosine_const ( ) {
26
+ let x = 0.0 ;
27
+ let cosine = unsafe { std:: intrinsics:: cosf32 ( x) } ;
28
+ assert ! ( fp_equals( cosine, 1.0 ) ) ;
29
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ // Check that `cosf64` returns the expected results.
5
+ // Note: The CBMC model for this function is an over-approximation that returns:
6
+ // * A nondet. value between -1 and 1
7
+ // * 1.0 if the argument is 0.0
8
+ #![ feature( core_intrinsics) ]
9
+
10
+ fn fp_equals ( value : f64 , expected : f64 ) -> bool {
11
+ let abs_diff = ( value - expected) . abs ( ) ;
12
+ abs_diff <= f64:: EPSILON
13
+ }
14
+
15
+ #[ kani:: proof]
16
+ fn cosine_range ( ) {
17
+ let x: f64 = kani:: any ( ) ;
18
+ kani:: assume ( x. is_finite ( ) ) ;
19
+ let cosine = unsafe { std:: intrinsics:: cosf64 ( x) } ;
20
+ assert ! ( cosine < 1.0 || fp_equals( cosine, 1.0 ) ) ;
21
+ assert ! ( cosine > -1.0 || fp_equals( cosine, -1.0 ) ) ;
22
+ }
23
+
24
+ #[ kani:: proof]
25
+ fn cosine_const ( ) {
26
+ let x = 0.0 ;
27
+ let cosine = unsafe { std:: intrinsics:: cosf64 ( x) } ;
28
+ assert ! ( fp_equals( cosine, 1.0 ) ) ;
29
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ // Check that `sinf32` returns the expected results.
5
+ // Note: The CBMC model for this function is an over-approximation that returns:
6
+ // * A nondet. value between -1 and 1
7
+ // * 0.0 if the argument is 0.0
8
+ #![ feature( core_intrinsics) ]
9
+
10
+ fn fp_equals ( value : f32 , expected : f32 ) -> bool {
11
+ let abs_diff = ( value - expected) . abs ( ) ;
12
+ abs_diff <= f32:: EPSILON
13
+ }
14
+
15
+ #[ kani:: proof]
16
+ fn sine_range ( ) {
17
+ let x: f32 = kani:: any ( ) ;
18
+ kani:: assume ( x. is_finite ( ) ) ;
19
+ let sine = unsafe { std:: intrinsics:: sinf32 ( x) } ;
20
+ assert ! ( sine < 1.0 || fp_equals( sine, 1.0 ) ) ;
21
+ assert ! ( sine > -1.0 || fp_equals( sine, -1.0 ) ) ;
22
+ }
23
+
24
+ #[ kani:: proof]
25
+ fn sine_const ( ) {
26
+ let x = 0.0 ;
27
+ let sine = unsafe { std:: intrinsics:: sinf32 ( x) } ;
28
+ assert ! ( fp_equals( sine, 0.0 ) ) ;
29
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ // Check that `sinf64` returns the expected results.
5
+ // Note: The CBMC model for this function is an over-approximation that returns:
6
+ // * A nondet. value between -1 and 1
7
+ // * 0.0 if the argument is 0.0
8
+ #![ feature( core_intrinsics) ]
9
+
10
+ fn fp_equals ( value : f64 , expected : f64 ) -> bool {
11
+ let abs_diff = ( value - expected) . abs ( ) ;
12
+ abs_diff <= f64:: EPSILON
13
+ }
14
+
15
+ #[ kani:: proof]
16
+ fn sine_range ( ) {
17
+ let x: f64 = kani:: any ( ) ;
18
+ kani:: assume ( x. is_finite ( ) ) ;
19
+ let sine = unsafe { std:: intrinsics:: sinf64 ( x) } ;
20
+ assert ! ( sine < 1.0 || fp_equals( sine, 1.0 ) ) ;
21
+ assert ! ( sine > -1.0 || fp_equals( sine, -1.0 ) ) ;
22
+ }
23
+
24
+ #[ kani:: proof]
25
+ fn sine_const ( ) {
26
+ let x = 0.0 ;
27
+ let sine = unsafe { std:: intrinsics:: sinf64 ( x) } ;
28
+ assert ! ( fp_equals( sine, 0.0 ) ) ;
29
+ }
You can’t perform that action at this time.
0 commit comments