Skip to content

Commit e1763fc

Browse files
committed
'float'
1 parent 163cd19 commit e1763fc

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

common/src/float_ops.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use num_bigint::{BigInt, ToBigInt};
22
use num_traits::{Float, Signed, ToPrimitive, Zero};
33

4+
///
45
pub fn ufrexp(value: f64) -> (f64, i32) {
56
if 0.0 == value {
67
(0.0, 0i32)
@@ -12,6 +13,22 @@ pub fn ufrexp(value: f64) -> (f64, i32) {
1213
}
1314
}
1415

16+
/// Equate an integer to a float.
17+
///
18+
/// Returns true if and only if, when converted to each others types, both are equal.
19+
///
20+
/// # Examples
21+
///
22+
/// ```
23+
/// use num_bigint::BigInt;
24+
/// use rustpython_common::float_ops::eq_int;
25+
/// let a = 1.0f64;
26+
/// let b = BigInt::from(1);
27+
/// let c = 2.0f64;
28+
/// assert!(eq_int(a, &b));
29+
/// assert!(!eq_int(c, &b));
30+
/// ```
31+
///
1532
pub fn eq_int(value: f64, other: &BigInt) -> bool {
1633
if let (Some(self_int), Some(other_float)) = (value.to_bigint(), other.to_f64()) {
1734
value == other_float && self_int == *other

0 commit comments

Comments
 (0)