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

Contracts & Harnesses for [f16, f128] to_int_unchecked #163

Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main' into c-0011-core-nums-junfeng-f16-f128-to-int-unc…
…hecked
  • Loading branch information
Yenyun035 authored Dec 4, 2024
commit 3466c30018db49166a23f243559c948b20bdc034
51 changes: 47 additions & 4 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ mod verify {
}
}

// Part 3: Float to Integer Conversion function Harness Generation Macros
// Part 3: Float to Integer Conversion function Harness Generation Macro
macro_rules! generate_to_int_unchecked_harness {
($floatType:ty, $($intType:ty, $harness_name:ident),+) => {
$(
Expand All @@ -1845,7 +1845,7 @@ mod verify {
)+
}
}
/*

// `unchecked_add` proofs
//
// Target types:
Expand Down Expand Up @@ -2141,8 +2141,51 @@ mod verify {
generate_wrapping_shift_harness!(u32, wrapping_shr, checked_wrapping_shr_u32);
generate_wrapping_shift_harness!(u64, wrapping_shr, checked_wrapping_shr_u64);
generate_wrapping_shift_harness!(u128, wrapping_shr, checked_wrapping_shr_u128);
generate_wrapping_shift_harness!(usize, wrapping_shr, checked_wrapping_shr_usize);*/
generate_wrapping_shift_harness!(usize, wrapping_shr, checked_wrapping_shr_usize);

// `f{16,32,64,128}::to_int_unchecked` proofs
//
// Target integer types:
// i{8,16,32,64,128,size} and u{8,16,32,64,128,size} -- 12 types in total
//
// Target contracts:
// 1. Float is not `NaN` and infinite
// 2. Float is representable in the return type `Int`, after truncating
// off its fractional part
// [requires(self.is_finite() && kani::float::float_to_int_in_range::<Self, Int>(self))]
//
// Target function:
// pub unsafe fn to_int_unchecked<Int>(self) -> Int where Self: FloatToInt<Int>
generate_to_int_unchecked_harness!(f32,
i8, checked_f32_to_int_unchecked_i8,
i16, checked_f32_to_int_unchecked_i16,
i32, checked_f32_to_int_unchecked_i32,
i64, checked_f32_to_int_unchecked_i64,
i128, checked_f32_to_int_unchecked_i128,
isize, checked_f32_to_int_unchecked_isize,
u8, checked_f32_to_int_unchecked_u8,
u16, checked_f32_to_int_unchecked_u16,
u32, checked_f32_to_int_unchecked_u32,
u64, checked_f32_to_int_unchecked_u64,
u128, checked_f32_to_int_unchecked_u128,
usize, checked_f32_to_int_unchecked_usize
);

generate_to_int_unchecked_harness!(f64,
i8, checked_f64_to_int_unchecked_i8,
i16, checked_f64_to_int_unchecked_i16,
i32, checked_f64_to_int_unchecked_i32,
i64, checked_f64_to_int_unchecked_i64,
i128, checked_f64_to_int_unchecked_i128,
isize, checked_f64_to_int_unchecked_isize,
u8, checked_f64_to_int_unchecked_u8,
u16, checked_f64_to_int_unchecked_u16,
u32, checked_f64_to_int_unchecked_u32,
u64, checked_f64_to_int_unchecked_u64,
u128, checked_f64_to_int_unchecked_u128,
usize, checked_f64_to_int_unchecked_usize
);

generate_to_int_unchecked_harness!(f16,
i8, checked_f16_to_int_unchecked_i8,
i16, checked_f16_to_int_unchecked_i16,
Expand All @@ -2157,7 +2200,7 @@ mod verify {
u128, checked_f16_to_int_unchecked_u128,
usize, checked_f16_to_int_unchecked_usize
);

generate_to_int_unchecked_harness!(f128,
i8, checked_f128_to_int_unchecked_i8,
i16, checked_f128_to_int_unchecked_i16,
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.