Skip to content

Commit d863bc2

Browse files
committed
1 parent d19f45a commit d863bc2

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

Diff for: src/math/mod.rs

+92
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,95 @@ fn with_set_low_word(f: f64, lo: u32) -> f64 {
332332
fn combine_words(hi: u32, lo: u32) -> f64 {
333333
f64::from_bits((hi as u64) << 32 | lo as u64)
334334
}
335+
336+
mod fdlibm {
337+
/* @(#)fdlibm.h 5.1 93/09/24 */
338+
/*
339+
* ====================================================
340+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
341+
*
342+
* Developed at SunPro, a Sun Microsystems, Inc. business.
343+
* Permission to use, copy, modify, and distribute this
344+
* software is freely granted, provided that this notice
345+
* is preserved.
346+
* ====================================================
347+
*/
348+
349+
#![allow(dead_code)] // not deadcode, just for debug and warnings
350+
351+
/* Most routines need to check whether a float is finite, infinite, or not a
352+
number, and many need to know whether the result of an operation will
353+
overflow. These conditions depend on whether the largest exponent is
354+
used for NaNs & infinities, or whether it's used for finite numbers. */
355+
356+
/// True if a positive float with bitmask X is finite.
357+
#[inline]
358+
#[allow(non_snake_case)]
359+
pub fn FLT_UWORD_IS_FINITE(x: u32) -> bool {
360+
x < 0x7f80_0000
361+
}
362+
363+
/// True if a positive float with bitmask X is not a number.
364+
#[inline]
365+
#[allow(non_snake_case)]
366+
pub fn FLT_UWORD_IS_NAN(x: u32) -> bool {
367+
x > 0x7f80_0000
368+
}
369+
370+
/// True if a positive float with bitmask X is +infinity.
371+
#[inline]
372+
#[allow(non_snake_case)]
373+
pub fn FLT_UWORD_IS_INFINITE(x: u32) -> bool {
374+
x == 0x7f80_0000
375+
}
376+
377+
/// The bitmask of FLT_MAX.
378+
pub const FLT_UWORD_MAX: u32 = 0x7f7f_ffff;
379+
/// The bitmask of FLT_MAX/2.
380+
pub const FLT_UWORD_HALF_MAX: u32 = FLT_UWORD_MAX - (1 << 23);
381+
/// The bitmask of the largest finite exponent (129 if the largest
382+
/// exponent is used for finite numbers, 128 otherwise).
383+
pub const FLT_UWORD_EXP_MAX: u32 = 0x4300_0000;
384+
/// The bitmask of log(FLT_MAX), rounded down. This value is the largest
385+
/// input that can be passed to exp() without producing overflow.
386+
pub const FLT_UWORD_LOG_MAX: u32 = 0x42b1_7217;
387+
/// The bitmask of log(2*FLT_MAX), rounded down. This value is the
388+
/// largest input than can be passed to cosh() without producing
389+
/// overflow.
390+
pub const FLT_UWORD_LOG_2MAX: u32 = 0x42b2_d4fc;
391+
/// The largest biased exponent that can be used for finite numbers
392+
/// (255 if the largest exponent is used for finite numbers, 254
393+
/// otherwise)
394+
pub const FLT_LARGEST_EXP: u32 = FLT_UWORD_MAX >> 23;
395+
pub const HUGE: f32 = 3.402_823_466_385_288_60e+38;
396+
397+
/* Many routines check for zero and subnormal numbers. Such things depend
398+
on whether the target supports denormals or not */
399+
400+
/// True if a positive float with bitmask X is +0. Without denormals,
401+
/// any float with a zero exponent is a +0 representation. With
402+
/// denormals, the only +0 representation is a 0 bitmask.
403+
#[inline]
404+
#[allow(non_snake_case)]
405+
pub fn FLT_UWORD_IS_ZERO(x: u32) -> bool {
406+
x == 0
407+
}
408+
409+
/// True if a non-zero positive float with bitmask X is subnormal.
410+
/// (Routines should check for zeros first.)
411+
#[inline]
412+
#[allow(non_snake_case)]
413+
pub fn FLT_UWORD_IS_SUBNORMAL(x: u32) -> bool {
414+
x < 0x0080_0000
415+
}
416+
417+
/// The bitmask of the smallest float above +0. Call this number REAL_FLT_MIN...
418+
pub const FLT_UWORD_MIN: u32 = 0x0000_0001;
419+
/// The bitmask of the float representation of REAL_FLT_MIN's exponent.
420+
pub const FLT_UWORD_EXP_MIN: u32 = 0x4316_0000;
421+
/// The bitmask of |log(REAL_FLT_MIN)|, rounding down.
422+
pub const FLT_UWORD_LOG_MIN: u32 = 0x42cf_f1b5;
423+
/// REAL_FLT_MIN's exponent - EXP_BIAS (1 if denormals are not supported,
424+
/// -22 if they are).
425+
pub const FLT_SMALLEST_EXP: i32 = -22;
426+
}

0 commit comments

Comments
 (0)