@@ -2,6 +2,7 @@ use core::f64;
22use malachite_bigint:: { BigInt , ToBigInt } ;
33use num_traits:: { Signed , ToPrimitive } ;
44
5+ #[ must_use]
56pub const fn decompose_float ( value : f64 ) -> ( f64 , i32 ) {
67 if 0.0 == value {
78 ( 0.0 , 0i32 )
@@ -29,6 +30,7 @@ pub const fn decompose_float(value: f64) -> (f64, i32) {
2930/// assert!(!eq_int(c, &b));
3031/// ```
3132///
33+ #[ must_use]
3234pub fn eq_int ( value : f64 , other : & BigInt ) -> bool {
3335 if let ( Some ( self_int) , Some ( other_float) ) = ( value. to_bigint ( ) , other. to_f64 ( ) ) {
3436 value == other_float && self_int == * other
@@ -37,6 +39,7 @@ pub fn eq_int(value: f64, other: &BigInt) -> bool {
3739 }
3840}
3941
42+ #[ must_use]
4043pub fn lt_int ( value : f64 , other_int : & BigInt ) -> bool {
4144 match ( value. to_bigint ( ) , other_int. to_f64 ( ) ) {
4245 ( Some ( self_int) , Some ( other_float) ) => value < other_float || self_int < * other_int,
@@ -50,6 +53,7 @@ pub fn lt_int(value: f64, other_int: &BigInt) -> bool {
5053 }
5154}
5255
56+ #[ must_use]
5357pub fn gt_int ( value : f64 , other_int : & BigInt ) -> bool {
5458 match ( value. to_bigint ( ) , other_int. to_f64 ( ) ) {
5559 ( Some ( self_int) , Some ( other_float) ) => value > other_float || self_int > * other_int,
@@ -63,21 +67,25 @@ pub fn gt_int(value: f64, other_int: &BigInt) -> bool {
6367 }
6468}
6569
70+ #[ must_use]
6671pub const fn div ( v1 : f64 , v2 : f64 ) -> Option < f64 > {
6772 if v2 != 0.0 { Some ( v1 / v2) } else { None }
6873}
6974
75+ #[ must_use]
7076pub fn mod_ ( v1 : f64 , v2 : f64 ) -> Option < f64 > {
7177 divmod ( v1, v2) . map ( |( _, m) | m)
7278}
7379
80+ #[ must_use]
7481pub fn floordiv ( v1 : f64 , v2 : f64 ) -> Option < f64 > {
7582 divmod ( v1, v2) . map ( |( d, _) | d)
7683}
7784
7885// Canonical (floordiv, mod) for floats matching CPython's _float_div_mod
7986// (Objects/floatobject.c). `mod_` and `floordiv` delegate here so that
8087// `divmod(a, b) == (a // b, a % b)` holds by construction.
88+ #[ must_use]
8189pub fn divmod ( v1 : f64 , v2 : f64 ) -> Option < ( f64 , f64 ) > {
8290 if v2 == 0.0 {
8391 return None ;
@@ -108,6 +116,7 @@ pub fn divmod(v1: f64, v2: f64) -> Option<(f64, f64)> {
108116
109117// nextafter algorithm based off of https://gitlab.com/bronsonbdevost/next_afterf
110118#[ allow( clippy:: float_cmp) ]
119+ #[ must_use]
111120pub fn nextafter ( x : f64 , y : f64 ) -> f64 {
112121 if x == y {
113122 y
@@ -130,6 +139,7 @@ pub fn nextafter(x: f64, y: f64) -> f64 {
130139}
131140
132141#[ allow( clippy:: float_cmp) ]
142+ #[ must_use]
133143pub fn nextafter_with_steps ( x : f64 , y : f64 , steps : u64 ) -> f64 {
134144 if x == y {
135145 y
@@ -192,6 +202,7 @@ pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {
192202 }
193203}
194204
205+ #[ must_use]
195206pub fn ulp ( x : f64 ) -> f64 {
196207 if x. is_nan ( ) {
197208 return x;
@@ -207,6 +218,7 @@ pub fn ulp(x: f64) -> f64 {
207218 }
208219}
209220
221+ #[ must_use]
210222pub fn round_float_digits ( x : f64 , ndigits : i32 ) -> Option < f64 > {
211223 // Mirror CPython's `float.__round__` (Objects/floatobject.c), which uses
212224 // `_Py_dg_dtoa` to round at the decimal level. Multiplying by 10**ndigits
0 commit comments