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

Ieee special values #2367

Merged
merged 4 commits into from
Dec 4, 2024
Merged
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
32 changes: 32 additions & 0 deletions tools/data-conversion/src/float_special_values
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use num_bigint::BigUint;
use std::str::FromStr;

pub struct IntermediateRepresentation {
pub sign: bool,
pub mantissa: BigUint,
pub exponent: i64, // Arbitrary precision exponent
}

impl IntermediateRepresentation {
// Function to check if the value is NaN
pub fn is_nan(&self, bit_width: usize) -> bool {
let max_exponent_value = (1 << (bit_width - 1)) - 1; // Max exponent for NaN
self.exponent == max_exponent_value as i64 && !self.mantissa.is_zero()
}

// Function to check if the value is infinity
pub fn is_infinity(&self, bit_width: usize) -> bool {
let max_exponent_value = (1 << (bit_width - 1)) - 1; // Max exponent for infinity
self.exponent == max_exponent_value as i64 && self.mantissa.is_zero()
}

// Function to check if the value is denormalized
pub fn is_denormalized(&self) -> bool {
self.exponent == 0 && !self.mantissa.is_zero()
}

// Function to check if the value is zero
pub fn is_zero(&self) -> bool {
self.exponent == 0 && self.mantissa.is_zero()
}
}
Loading