#[test] fn to_f32_test() { // underflow let x = ExtendedFloat {
mant: 9223372036854775808,
exp: -213,
};
assert_eq!(x.into_float::<f32>(), 0.0);
// min value let x = ExtendedFloat {
mant: 9223372036854775808,
exp: -212,
};
assert_eq!(x.into_float::<f32>(), 1e-45);
// 1.0e-40 let x = ExtendedFloat {
mant: 10043308644012916736,
exp: -196,
};
assert_eq!(x.into_float::<f32>(), 1e-40);
// 1.0e-20 let x = ExtendedFloat {
mant: 13611294244890214400,
exp: -130,
};
assert_eq!(x.into_float::<f32>(), 1e-20);
// 1.0 let x = ExtendedFloat {
mant: 9223372036854775808,
exp: -63,
};
assert_eq!(x.into_float::<f32>(), 1.0);
// 1e20 let x = ExtendedFloat {
mant: 12500000250510966784,
exp: 3,
};
assert_eq!(x.into_float::<f32>(), 1e20);
// max value let x = ExtendedFloat {
mant: 18446740775174668288,
exp: 64,
};
assert_eq!(x.into_float::<f32>(), 3.402823e38);
// almost max, high exp let x = ExtendedFloat {
mant: 1048575,
exp: 108,
};
assert_eq!(x.into_float::<f32>(), 3.4028204e38);
// max value + 1 let x = ExtendedFloat {
mant: 16777216,
exp: 104,
};
assert_eq!(x.into_float::<f32>(), f32::INFINITY);
// max value + 1 let x = ExtendedFloat {
mant: 1048576,
exp: 108,
};
assert_eq!(x.into_float::<f32>(), f32::INFINITY);
// 1e40 let x = ExtendedFloat {
mant: 16940658945086007296,
exp: 69,
};
assert_eq!(x.into_float::<f32>(), f32::INFINITY);
// Integers. for int in &INTEGERS { let fp = ExtendedFloat { mant: *int, exp: 0 };
assert_eq!(fp.into_float::<f32>(), *int as f32, "{:?} as f32", *int);
}
}
#[test] fn to_f64_test() { // underflow let x = ExtendedFloat {
mant: 9223372036854775808,
exp: -1138,
};
assert_eq!(x.into_float::<f64>(), 0.0);
// min value let x = ExtendedFloat {
mant: 9223372036854775808,
exp: -1137,
};
assert_eq!(x.into_float::<f64>(), 5e-324);
// 1.0e-250 let x = ExtendedFloat {
mant: 13207363278391631872,
exp: -894,
};
assert_eq!(x.into_float::<f64>(), 1e-250);
// 1.0e-150 let x = ExtendedFloat {
mant: 15095849699286165504,
exp: -562,
};
assert_eq!(x.into_float::<f64>(), 1e-150);
// 1.0e-45 let x = ExtendedFloat {
mant: 13164036458569648128,
exp: -213,
};
assert_eq!(x.into_float::<f64>(), 1e-45);
// 1.0e-40 let x = ExtendedFloat {
mant: 10043362776618688512,
exp: -196,
};
assert_eq!(x.into_float::<f64>(), 1e-40);
// 1.0e-20 let x = ExtendedFloat {
mant: 13611294676837537792,
exp: -130,
};
assert_eq!(x.into_float::<f64>(), 1e-20);
// 1.0 let x = ExtendedFloat {
mant: 9223372036854775808,
exp: -63,
};
assert_eq!(x.into_float::<f64>(), 1.0);
// 1e20 let x = ExtendedFloat {
mant: 12500000000000000000,
exp: 3,
};
assert_eq!(x.into_float::<f64>(), 1e20);
// 1e40 let x = ExtendedFloat {
mant: 16940658945086007296,
exp: 69,
};
assert_eq!(x.into_float::<f64>(), 1e40);
// 1e150 let x = ExtendedFloat {
mant: 11270725851789228032,
exp: 435,
};
assert_eq!(x.into_float::<f64>(), 1e150);
// 1e250 let x = ExtendedFloat {
mant: 12882297539194265600,
exp: 767,
};
assert_eq!(x.into_float::<f64>(), 1e250);
// max value let x = ExtendedFloat {
mant: 9007199254740991,
exp: 971,
};
assert_eq!(x.into_float::<f64>(), 1.7976931348623157e308);
// max value let x = ExtendedFloat {
mant: 18446744073709549568,
exp: 960,
};
assert_eq!(x.into_float::<f64>(), 1.7976931348623157e308);
// overflow let x = ExtendedFloat {
mant: 9007199254740992,
exp: 971,
};
assert_eq!(x.into_float::<f64>(), f64::INFINITY);
// overflow let x = ExtendedFloat {
mant: 18446744073709549568,
exp: 961,
};
assert_eq!(x.into_float::<f64>(), f64::INFINITY);
// Underflow // Adapted from failures in strtod. let x = ExtendedFloat {
exp: -1139,
mant: 18446744073709550712,
};
assert_eq!(x.into_float::<f64>(), 0.0);
let x = ExtendedFloat {
exp: -1139,
mant: 18446744073709551460,
};
assert_eq!(x.into_float::<f64>(), 0.0);
let x = ExtendedFloat {
exp: -1138,
mant: 9223372036854776103,
};
assert_eq!(x.into_float::<f64>(), 5e-324);
// Integers. for int in &INTEGERS { let fp = ExtendedFloat { mant: *int, exp: 0 };
assert_eq!(fp.into_float::<f64>(), *int as f64, "{:?} as f64", *int);
}
}
// OPERATIONS
fn check_mul(a: ExtendedFloat, b: ExtendedFloat, c: ExtendedFloat) { let r = a.mul(&b);
assert_eq!(r, c);
}
#[test] fn mul_test() { // Normalized (64-bit mantissa) let a = ExtendedFloat {
mant: 13164036458569648128,
exp: -213,
}; let b = ExtendedFloat {
mant: 9223372036854775808,
exp: -62,
}; let c = ExtendedFloat {
mant: 6582018229284824064,
exp: -211,
};
check_mul(a, b, c);
// Check both values need high bits set. let a = ExtendedFloat {
mant: 1 << 32,
exp: -31,
}; let b = ExtendedFloat {
mant: 1 << 32,
exp: -31,
};
assert_eq!(a.mul(&b).into_float::<f64>(), 4.0);
// Check both values need high bits set. let a = ExtendedFloat {
mant: 10 << 31,
exp: -31,
}; let b = ExtendedFloat {
mant: 10 << 31,
exp: -31,
};
assert_eq!(a.mul(&b).into_float::<f64>(), 100.0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.