Skip to content

Commit e0cd060

Browse files
committed
added useful constants to math
1 parent 8319b5a commit e0cd060

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/libcore/f32.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export
1515
frexp, ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin,
1616
sinh, sqrt, tan, tanh, trunc, t;
1717

18+
export radix, mantissa_digits, digits, epsilon, min_value, max_value,
19+
min_exp, max_exp, min_10_exp, max_10_exp;
20+
1821
export consts;
1922

2023
type t = f32;
@@ -114,6 +117,27 @@ mod consts {
114117
const ln_10: f32 = 2.30258509299404568401799145468436421f32;
115118
}
116119

120+
// These are not defined inside consts:: for consistency with
121+
// the integer types
122+
123+
// PORT check per architecture
124+
125+
const radix: uint = 2u;
126+
127+
const mantissa_digits: uint = 24u;
128+
const digits: uint = 6u;
129+
130+
const epsilon: f32 = 1.19209290e-07f32;
131+
132+
const min_value: f32 = 1.17549435e-38f32;
133+
const max_value: f32 = 3.40282347e+38f32;
134+
135+
const min_exp: int = -125;
136+
const max_exp: int = 128;
137+
138+
const min_10_exp: int = -37;
139+
const max_10_exp: int = 38;
140+
117141
//
118142
// Local Variables:
119143
// mode: rust

src/libcore/f64.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export
1515
frexp, ldexp, ln, ln1p, log10, log2, modf, rint, round, pow, sin,
1616
sinh, sqrt, tan, tanh, trunc, t;
1717

18+
export radix, mantissa_digits, digits, epsilon, min_value, max_value,
19+
min_exp, max_exp, min_10_exp, max_10_exp;
20+
1821
export consts;
1922

2023
type t = f64;
@@ -114,6 +117,27 @@ mod consts {
114117
const ln_10: f64 = 2.30258509299404568401799145468436421f64;
115118
}
116119

120+
// These are not defined inside consts:: for consistency with
121+
// the integer types
122+
123+
// PORT check per architecture
124+
125+
const radix: uint = 2u;
126+
127+
const mantissa_digits: uint = 53u;
128+
const digits: uint = 15u;
129+
130+
const epsilon: f64 = 2.2204460492503131e-16f64;
131+
132+
const min_value: f64 = 2.2250738585072014e-308f64;
133+
const max_value: f64 = 1.7976931348623157e+308f64;
134+
135+
const min_exp: int = -1021;
136+
const max_exp: int = 1024;
137+
138+
const min_10_exp: int = -307;
139+
const max_10_exp: int = 308;
140+
117141
//
118142
// Local Variables:
119143
// mode: rust

src/libcore/float.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,31 @@ Returns the integral value nearest to but no larger in magnitude than `x`
719719
pure fn trunc(x: float) -> float
720720
{ ret m_float::trunc(x as m_float) as float }
721721

722+
/*
723+
724+
FIXME implement this as soon as const expressions may refer to each other
725+
726+
export radix, mantissa_digits, digits, epsilon, min_value, max_value,
727+
min_exp, max_exp, min_10_exp, max_10_exp;
728+
729+
const radix: m_float = m_float::radix as m_float;
730+
731+
const mantissa_digits: m_float = m_float::mantissa_digits as m_float;
732+
const digits: m_float = m_float::digits as m_float;
733+
734+
const epsilon: m_float = m_float::epsilon as m_float;
735+
736+
const min_value: m_float = m_float::min_value as m_float;
737+
const max_value: m_float = m_float::max_value as m_float;
738+
739+
const min_exp: m_float = m_float::min_exp as m_float;
740+
const max_exp: m_float = m_float::max_exp as m_float;
741+
742+
const min_10_exp: m_float = m_float::min_10_exp as m_float;
743+
const max_10_exp: m_float = m_float::max_10_exp as m_float;
744+
745+
*/
746+
722747
//
723748
// Local Variables:
724749
// mode: rust
@@ -728,3 +753,8 @@ pure fn trunc(x: float) -> float
728753
// buffer-file-coding-system: utf-8-unix
729754
// End:
730755
//
756+
757+
758+
759+
760+

0 commit comments

Comments
 (0)