1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594 |
- use core::mem;
- use core::ops::Neg;
- use core::num::FpCategory;
- #[cfg(feature = "std")]
- use std::f32;
- use {Num, ToPrimitive};
- #[cfg(feature = "std")]
- use NumCast;
- pub trait FloatCore: Num + Neg<Output = Self> + PartialOrd + Copy {
-
- fn infinity() -> Self;
-
- fn neg_infinity() -> Self;
-
- fn nan() -> Self;
-
- #[inline]
- fn is_nan(self) -> bool {
- self != self
- }
-
- #[inline]
- fn is_infinite(self) -> bool {
- self == Self::infinity() || self == Self::neg_infinity()
- }
-
- #[inline]
- fn is_finite(self) -> bool {
- !(self.is_nan() || self.is_infinite())
- }
-
- #[inline]
- fn is_normal(self) -> bool {
- self.classify() == FpCategory::Normal
- }
-
-
-
- fn classify(self) -> FpCategory;
-
-
- #[inline]
- fn abs(self) -> Self {
- if self.is_sign_positive() {
- return self;
- }
- if self.is_sign_negative() {
- return -self;
- }
- Self::nan()
- }
-
-
-
-
-
- #[inline]
- fn signum(self) -> Self {
- if self.is_sign_positive() {
- return Self::one();
- }
- if self.is_sign_negative() {
- return -Self::one();
- }
- Self::nan()
- }
-
-
- #[inline]
- fn is_sign_positive(self) -> bool {
- self > Self::zero() || (Self::one() / self) == Self::infinity()
- }
-
-
- #[inline]
- fn is_sign_negative(self) -> bool {
- self < Self::zero() || (Self::one() / self) == Self::neg_infinity()
- }
-
-
-
- #[inline]
- fn min(self, other: Self) -> Self {
- if self.is_nan() {
- return other;
- }
- if other.is_nan() {
- return self;
- }
- if self < other { self } else { other }
- }
-
-
-
- #[inline]
- fn max(self, other: Self) -> Self {
- if self.is_nan() {
- return other;
- }
- if other.is_nan() {
- return self;
- }
- if self > other { self } else { other }
- }
-
- #[inline]
- fn recip(self) -> Self {
- Self::one() / self
- }
-
-
-
- #[inline]
- fn powi(mut self, mut exp: i32) -> Self {
- if exp < 0 {
- exp = -exp;
- self = self.recip();
- }
-
- super::pow(self, exp.to_usize().unwrap())
- }
-
- fn to_degrees(self) -> Self;
-
- fn to_radians(self) -> Self;
- }
- impl FloatCore for f32 {
- #[inline]
- fn infinity() -> Self {
- ::core::f32::INFINITY
- }
- #[inline]
- fn neg_infinity() -> Self {
- ::core::f32::NEG_INFINITY
- }
- #[inline]
- fn nan() -> Self {
- ::core::f32::NAN
- }
- #[inline]
- fn classify(self) -> FpCategory {
- const EXP_MASK: u32 = 0x7f800000;
- const MAN_MASK: u32 = 0x007fffff;
- let bits: u32 = unsafe { mem::transmute(self) };
- match (bits & MAN_MASK, bits & EXP_MASK) {
- (0, 0) => FpCategory::Zero,
- (_, 0) => FpCategory::Subnormal,
- (0, EXP_MASK) => FpCategory::Infinite,
- (_, EXP_MASK) => FpCategory::Nan,
- _ => FpCategory::Normal,
- }
- }
- #[inline]
- fn to_degrees(self) -> Self {
- self * (180.0 / ::core::f32::consts::PI)
- }
- #[inline]
- fn to_radians(self) -> Self {
- self * (::core::f32::consts::PI / 180.0)
- }
- }
- impl FloatCore for f64 {
- #[inline]
- fn infinity() -> Self {
- ::core::f64::INFINITY
- }
- #[inline]
- fn neg_infinity() -> Self {
- ::core::f64::NEG_INFINITY
- }
- #[inline]
- fn nan() -> Self {
- ::core::f64::NAN
- }
- #[inline]
- fn classify(self) -> FpCategory {
- const EXP_MASK: u64 = 0x7ff0000000000000;
- const MAN_MASK: u64 = 0x000fffffffffffff;
- let bits: u64 = unsafe { mem::transmute(self) };
- match (bits & MAN_MASK, bits & EXP_MASK) {
- (0, 0) => FpCategory::Zero,
- (_, 0) => FpCategory::Subnormal,
- (0, EXP_MASK) => FpCategory::Infinite,
- (_, EXP_MASK) => FpCategory::Nan,
- _ => FpCategory::Normal,
- }
- }
- #[inline]
- fn to_degrees(self) -> Self {
- self * (180.0 / ::core::f64::consts::PI)
- }
- #[inline]
- fn to_radians(self) -> Self {
- self * (::core::f64::consts::PI / 180.0)
- }
- }
- #[cfg(feature = "std")]
- pub trait Float
- : Num
- + Copy
- + NumCast
- + PartialOrd
- + Neg<Output = Self>
- {
-
-
-
-
-
-
-
-
-
- fn nan() -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn infinity() -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn neg_infinity() -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn neg_zero() -> Self;
-
-
-
-
-
-
-
-
-
-
- fn min_value() -> Self;
-
-
-
-
-
-
-
-
-
-
- fn min_positive_value() -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn epsilon() -> Self {
- Self::from(f32::EPSILON).expect("Unable to cast from f32::EPSILON")
- }
-
-
-
-
-
-
-
-
-
- fn max_value() -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn is_nan(self) -> bool;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn is_infinite(self) -> bool;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn is_finite(self) -> bool;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn is_normal(self) -> bool;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn classify(self) -> FpCategory;
-
-
-
-
-
-
-
-
-
-
-
- fn floor(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
- fn ceil(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn round(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
- fn trunc(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn fract(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn abs(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn signum(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn is_sign_positive(self) -> bool;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn is_sign_negative(self) -> bool;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn mul_add(self, a: Self, b: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
- fn recip(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn powi(self, n: i32) -> Self;
-
-
-
-
-
-
-
-
-
-
- fn powf(self, n: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn sqrt(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn exp(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn exp2(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn ln(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn log(self, base: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn log2(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn log10(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- fn to_degrees(self) -> Self {
- let halfpi = Self::zero().acos();
- let ninety = Self::from(90u8).unwrap();
- self * ninety / halfpi
- }
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- fn to_radians(self) -> Self {
- let halfpi = Self::zero().acos();
- let ninety = Self::from(90u8).unwrap();
- self * halfpi / ninety
- }
-
-
-
-
-
-
-
-
-
-
- fn max(self, other: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
- fn min(self, other: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn abs_sub(self, other: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn cbrt(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn hypot(self, other: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn sin(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn cos(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
- fn tan(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn asin(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn acos(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn atan(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn atan2(self, other: Self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn sin_cos(self) -> (Self, Self);
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn exp_m1(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn ln_1p(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn sinh(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn cosh(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn tanh(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn asinh(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
- fn acosh(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn atanh(self) -> Self;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fn integer_decode(self) -> (u64, i16, i8);
- }
- #[cfg(feature = "std")]
- macro_rules! float_impl {
- ($T:ident $decode:ident) => (
- impl Float for $T {
- #[inline]
- fn nan() -> Self {
- ::std::$T::NAN
- }
- #[inline]
- fn infinity() -> Self {
- ::std::$T::INFINITY
- }
- #[inline]
- fn neg_infinity() -> Self {
- ::std::$T::NEG_INFINITY
- }
- #[inline]
- fn neg_zero() -> Self {
- -0.0
- }
- #[inline]
- fn min_value() -> Self {
- ::std::$T::MIN
- }
- #[inline]
- fn min_positive_value() -> Self {
- ::std::$T::MIN_POSITIVE
- }
- #[inline]
- fn epsilon() -> Self {
- ::std::$T::EPSILON
- }
- #[inline]
- fn max_value() -> Self {
- ::std::$T::MAX
- }
- #[inline]
- fn is_nan(self) -> bool {
- <$T>::is_nan(self)
- }
- #[inline]
- fn is_infinite(self) -> bool {
- <$T>::is_infinite(self)
- }
- #[inline]
- fn is_finite(self) -> bool {
- <$T>::is_finite(self)
- }
- #[inline]
- fn is_normal(self) -> bool {
- <$T>::is_normal(self)
- }
- #[inline]
- fn classify(self) -> FpCategory {
- <$T>::classify(self)
- }
- #[inline]
- fn floor(self) -> Self {
- <$T>::floor(self)
- }
- #[inline]
- fn ceil(self) -> Self {
- <$T>::ceil(self)
- }
- #[inline]
- fn round(self) -> Self {
- <$T>::round(self)
- }
- #[inline]
- fn trunc(self) -> Self {
- <$T>::trunc(self)
- }
- #[inline]
- fn fract(self) -> Self {
- <$T>::fract(self)
- }
- #[inline]
- fn abs(self) -> Self {
- <$T>::abs(self)
- }
- #[inline]
- fn signum(self) -> Self {
- <$T>::signum(self)
- }
- #[inline]
- fn is_sign_positive(self) -> bool {
- <$T>::is_sign_positive(self)
- }
- #[inline]
- fn is_sign_negative(self) -> bool {
- <$T>::is_sign_negative(self)
- }
- #[inline]
- fn mul_add(self, a: Self, b: Self) -> Self {
- <$T>::mul_add(self, a, b)
- }
- #[inline]
- fn recip(self) -> Self {
- <$T>::recip(self)
- }
- #[inline]
- fn powi(self, n: i32) -> Self {
- <$T>::powi(self, n)
- }
- #[inline]
- fn powf(self, n: Self) -> Self {
- <$T>::powf(self, n)
- }
- #[inline]
- fn sqrt(self) -> Self {
- <$T>::sqrt(self)
- }
- #[inline]
- fn exp(self) -> Self {
- <$T>::exp(self)
- }
- #[inline]
- fn exp2(self) -> Self {
- <$T>::exp2(self)
- }
- #[inline]
- fn ln(self) -> Self {
- <$T>::ln(self)
- }
- #[inline]
- fn log(self, base: Self) -> Self {
- <$T>::log(self, base)
- }
- #[inline]
- fn log2(self) -> Self {
- <$T>::log2(self)
- }
- #[inline]
- fn log10(self) -> Self {
- <$T>::log10(self)
- }
- #[inline]
- fn to_degrees(self) -> Self {
-
-
- self * (180. / ::std::$T::consts::PI)
- }
- #[inline]
- fn to_radians(self) -> Self {
-
-
- self * (::std::$T::consts::PI / 180.)
- }
- #[inline]
- fn max(self, other: Self) -> Self {
- <$T>::max(self, other)
- }
- #[inline]
- fn min(self, other: Self) -> Self {
- <$T>::min(self, other)
- }
- #[inline]
- #[allow(deprecated)]
- fn abs_sub(self, other: Self) -> Self {
- <$T>::abs_sub(self, other)
- }
- #[inline]
- fn cbrt(self) -> Self {
- <$T>::cbrt(self)
- }
- #[inline]
- fn hypot(self, other: Self) -> Self {
- <$T>::hypot(self, other)
- }
- #[inline]
- fn sin(self) -> Self {
- <$T>::sin(self)
- }
- #[inline]
- fn cos(self) -> Self {
- <$T>::cos(self)
- }
- #[inline]
- fn tan(self) -> Self {
- <$T>::tan(self)
- }
- #[inline]
- fn asin(self) -> Self {
- <$T>::asin(self)
- }
- #[inline]
- fn acos(self) -> Self {
- <$T>::acos(self)
- }
- #[inline]
- fn atan(self) -> Self {
- <$T>::atan(self)
- }
- #[inline]
- fn atan2(self, other: Self) -> Self {
- <$T>::atan2(self, other)
- }
- #[inline]
- fn sin_cos(self) -> (Self, Self) {
- <$T>::sin_cos(self)
- }
- #[inline]
- fn exp_m1(self) -> Self {
- <$T>::exp_m1(self)
- }
- #[inline]
- fn ln_1p(self) -> Self {
- <$T>::ln_1p(self)
- }
- #[inline]
- fn sinh(self) -> Self {
- <$T>::sinh(self)
- }
- #[inline]
- fn cosh(self) -> Self {
- <$T>::cosh(self)
- }
- #[inline]
- fn tanh(self) -> Self {
- <$T>::tanh(self)
- }
- #[inline]
- fn asinh(self) -> Self {
- <$T>::asinh(self)
- }
- #[inline]
- fn acosh(self) -> Self {
- <$T>::acosh(self)
- }
- #[inline]
- fn atanh(self) -> Self {
- <$T>::atanh(self)
- }
- #[inline]
- fn integer_decode(self) -> (u64, i16, i8) {
- $decode(self)
- }
- }
- )
- }
- #[cfg(feature = "std")]
- fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
- let bits: u32 = unsafe { mem::transmute(f) };
- let sign: i8 = if bits >> 31 == 0 {
- 1
- } else {
- -1
- };
- let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
- let mantissa = if exponent == 0 {
- (bits & 0x7fffff) << 1
- } else {
- (bits & 0x7fffff) | 0x800000
- };
-
- exponent -= 127 + 23;
- (mantissa as u64, exponent, sign)
- }
- #[cfg(feature = "std")]
- fn integer_decode_f64(f: f64) -> (u64, i16, i8) {
- let bits: u64 = unsafe { mem::transmute(f) };
- let sign: i8 = if bits >> 63 == 0 {
- 1
- } else {
- -1
- };
- let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
- let mantissa = if exponent == 0 {
- (bits & 0xfffffffffffff) << 1
- } else {
- (bits & 0xfffffffffffff) | 0x10000000000000
- };
-
- exponent -= 1023 + 52;
- (mantissa, exponent, sign)
- }
- #[cfg(feature = "std")]
- float_impl!(f32 integer_decode_f32);
- #[cfg(feature = "std")]
- float_impl!(f64 integer_decode_f64);
- macro_rules! float_const_impl {
- ($(#[$doc:meta] $constant:ident,)+) => (
- #[allow(non_snake_case)]
- pub trait FloatConst {
- $(#[$doc] fn $constant() -> Self;)+
- }
- float_const_impl! { @float f32, $($constant,)+ }
- float_const_impl! { @float f64, $($constant,)+ }
- );
- (@float $T:ident, $($constant:ident,)+) => (
- impl FloatConst for $T {
- $(
- #[inline]
- fn $constant() -> Self {
- ::core::$T::consts::$constant
- }
- )+
- }
- );
- }
- float_const_impl! {
- #[doc = "Return Euler’s number."]
- E,
- #[doc = "Return `1.0 / π`."]
- FRAC_1_PI,
- #[doc = "Return `1.0 / sqrt(2.0)`."]
- FRAC_1_SQRT_2,
- #[doc = "Return `2.0 / π`."]
- FRAC_2_PI,
- #[doc = "Return `2.0 / sqrt(π)`."]
- FRAC_2_SQRT_PI,
- #[doc = "Return `π / 2.0`."]
- FRAC_PI_2,
- #[doc = "Return `π / 3.0`."]
- FRAC_PI_3,
- #[doc = "Return `π / 4.0`."]
- FRAC_PI_4,
- #[doc = "Return `π / 6.0`."]
- FRAC_PI_6,
- #[doc = "Return `π / 8.0`."]
- FRAC_PI_8,
- #[doc = "Return `ln(10.0)`."]
- LN_10,
- #[doc = "Return `ln(2.0)`."]
- LN_2,
- #[doc = "Return `log10(e)`."]
- LOG10_E,
- #[doc = "Return `log2(e)`."]
- LOG2_E,
- #[doc = "Return Archimedes’ constant."]
- PI,
- #[doc = "Return `sqrt(2.0)`."]
- SQRT_2,
- }
- #[cfg(test)]
- mod tests {
- use core::f64::consts;
- const DEG_RAD_PAIRS: [(f64, f64); 7] = [
- (0.0, 0.),
- (22.5, consts::FRAC_PI_8),
- (30.0, consts::FRAC_PI_6),
- (45.0, consts::FRAC_PI_4),
- (60.0, consts::FRAC_PI_3),
- (90.0, consts::FRAC_PI_2),
- (180.0, consts::PI),
- ];
- #[test]
- fn convert_deg_rad() {
- use float::FloatCore;
- for &(deg, rad) in &DEG_RAD_PAIRS {
- assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-6);
- assert!((FloatCore::to_radians(deg) - rad).abs() < 1e-6);
- let (deg, rad) = (deg as f32, rad as f32);
- assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-6);
- assert!((FloatCore::to_radians(deg) - rad).abs() < 1e-6);
- }
- }
- #[cfg(feature = "std")]
- #[test]
- fn convert_deg_rad_std() {
- for &(deg, rad) in &DEG_RAD_PAIRS {
- use Float;
- assert!((Float::to_degrees(rad) - deg).abs() < 1e-6);
- assert!((Float::to_radians(deg) - rad).abs() < 1e-6);
- let (deg, rad) = (deg as f32, rad as f32);
- assert!((Float::to_degrees(rad) - deg).abs() < 1e-6);
- assert!((Float::to_radians(deg) - rad).abs() < 1e-6);
- }
- }
- }
|