@@ -24,6 +24,8 @@ use core::ops::{
24
24
use core:: str:: FromStr ;
25
25
26
26
pub use num_traits:: float:: FloatCore ;
27
+ #[ cfg( any( feature = "std" , feature = "libm" ) ) ]
28
+ use num_traits:: real:: Real ;
27
29
use num_traits:: {
28
30
AsPrimitive , Bounded , FloatConst , FromPrimitive , Num , NumCast , One , Signed , ToPrimitive , Zero ,
29
31
} ;
@@ -1957,6 +1959,170 @@ impl<T: FloatCore> NumCast for NotNan<T> {
1957
1959
}
1958
1960
}
1959
1961
1962
+ #[ cfg( any( feature = "std" , feature = "libm" ) ) ]
1963
+ impl < T : Real + FloatCore > Real for NotNan < T > {
1964
+ fn min_value ( ) -> Self {
1965
+ NotNan ( <T as Real >:: min_value ( ) )
1966
+ }
1967
+ fn min_positive_value ( ) -> Self {
1968
+ NotNan ( <T as Real >:: min_positive_value ( ) )
1969
+ }
1970
+ fn epsilon ( ) -> Self {
1971
+ NotNan ( Real :: epsilon ( ) )
1972
+ }
1973
+ fn max_value ( ) -> Self {
1974
+ NotNan ( <T as Real >:: max_value ( ) )
1975
+ }
1976
+ fn floor ( self ) -> Self {
1977
+ NotNan ( Real :: floor ( self . 0 ) )
1978
+ }
1979
+ fn ceil ( self ) -> Self {
1980
+ NotNan ( Real :: ceil ( self . 0 ) )
1981
+ }
1982
+ fn round ( self ) -> Self {
1983
+ NotNan ( Real :: round ( self . 0 ) )
1984
+ }
1985
+ fn trunc ( self ) -> Self {
1986
+ NotNan ( Real :: trunc ( self . 0 ) )
1987
+ }
1988
+ fn fract ( self ) -> Self {
1989
+ NotNan ( Real :: fract ( self . 0 ) )
1990
+ }
1991
+ fn abs ( self ) -> Self {
1992
+ NotNan ( Real :: abs ( self . 0 ) )
1993
+ }
1994
+ fn signum ( self ) -> Self {
1995
+ NotNan ( Real :: signum ( self . 0 ) )
1996
+ }
1997
+ fn is_sign_positive ( self ) -> bool {
1998
+ Real :: is_sign_positive ( self . 0 )
1999
+ }
2000
+ fn is_sign_negative ( self ) -> bool {
2001
+ Real :: is_sign_negative ( self . 0 )
2002
+ }
2003
+ fn mul_add ( self , a : Self , b : Self ) -> Self {
2004
+ NotNan ( self . 0 . mul_add ( a. 0 , b. 0 ) )
2005
+ }
2006
+ fn recip ( self ) -> Self {
2007
+ NotNan ( Real :: recip ( self . 0 ) )
2008
+ }
2009
+ fn powi ( self , n : i32 ) -> Self {
2010
+ NotNan ( Real :: powi ( self . 0 , n) )
2011
+ }
2012
+ fn powf ( self , n : Self ) -> Self {
2013
+ // Panics if self < 0 and n is not an integer
2014
+ NotNan :: new ( self . 0 . powf ( n. 0 ) ) . expect ( "Power resulted in NaN" )
2015
+ }
2016
+ fn sqrt ( self ) -> Self {
2017
+ // Panics if self < 0
2018
+ NotNan :: new ( self . 0 . sqrt ( ) ) . expect ( "Square root resulted in NaN" )
2019
+ }
2020
+ fn exp ( self ) -> Self {
2021
+ NotNan ( self . 0 . exp ( ) )
2022
+ }
2023
+ fn exp2 ( self ) -> Self {
2024
+ NotNan ( self . 0 . exp2 ( ) )
2025
+ }
2026
+ fn ln ( self ) -> Self {
2027
+ // Panics if self <= 0
2028
+ NotNan :: new ( self . 0 . ln ( ) ) . expect ( "Natural logarithm resulted in NaN" )
2029
+ }
2030
+ fn log ( self , base : Self ) -> Self {
2031
+ // Panics if self <= 0 or base <= 0
2032
+ NotNan :: new ( self . 0 . log ( base. 0 ) ) . expect ( "Logarithm resulted in NaN" )
2033
+ }
2034
+ fn log2 ( self ) -> Self {
2035
+ // Panics if self <= 0
2036
+ NotNan :: new ( self . 0 . log2 ( ) ) . expect ( "Logarithm resulted in NaN" )
2037
+ }
2038
+ fn log10 ( self ) -> Self {
2039
+ // Panics if self <= 0
2040
+ NotNan :: new ( self . 0 . log10 ( ) ) . expect ( "Logarithm resulted in NaN" )
2041
+ }
2042
+ fn to_degrees ( self ) -> Self {
2043
+ NotNan ( Real :: to_degrees ( self . 0 ) )
2044
+ }
2045
+ fn to_radians ( self ) -> Self {
2046
+ NotNan ( Real :: to_radians ( self . 0 ) )
2047
+ }
2048
+ fn max ( self , other : Self ) -> Self {
2049
+ NotNan ( Real :: max ( self . 0 , other. 0 ) )
2050
+ }
2051
+ fn min ( self , other : Self ) -> Self {
2052
+ NotNan ( Real :: min ( self . 0 , other. 0 ) )
2053
+ }
2054
+ fn abs_sub ( self , other : Self ) -> Self {
2055
+ NotNan ( self . 0 . abs_sub ( other. 0 ) )
2056
+ }
2057
+ fn cbrt ( self ) -> Self {
2058
+ NotNan ( self . 0 . cbrt ( ) )
2059
+ }
2060
+ fn hypot ( self , other : Self ) -> Self {
2061
+ NotNan ( self . 0 . hypot ( other. 0 ) )
2062
+ }
2063
+ fn sin ( self ) -> Self {
2064
+ // Panics if self is +/-infinity
2065
+ NotNan :: new ( self . 0 . sin ( ) ) . expect ( "Sine resulted in NaN" )
2066
+ }
2067
+ fn cos ( self ) -> Self {
2068
+ // Panics if self is +/-infinity
2069
+ NotNan :: new ( self . 0 . cos ( ) ) . expect ( "Cosine resulted in NaN" )
2070
+ }
2071
+ fn tan ( self ) -> Self {
2072
+ // Panics if self is +/-infinity or self == pi/2 + k*pi
2073
+ NotNan :: new ( self . 0 . tan ( ) ) . expect ( "Tangent resulted in NaN" )
2074
+ }
2075
+ fn asin ( self ) -> Self {
2076
+ // Panics if self < -1.0 or self > 1.0
2077
+ NotNan :: new ( self . 0 . asin ( ) ) . expect ( "Arcsine resulted in NaN" )
2078
+ }
2079
+ fn acos ( self ) -> Self {
2080
+ // Panics if self < -1.0 or self > 1.0
2081
+ NotNan :: new ( self . 0 . acos ( ) ) . expect ( "Arccosine resulted in NaN" )
2082
+ }
2083
+ fn atan ( self ) -> Self {
2084
+ NotNan ( self . 0 . atan ( ) )
2085
+ }
2086
+ fn atan2 ( self , other : Self ) -> Self {
2087
+ NotNan ( self . 0 . atan2 ( other. 0 ) )
2088
+ }
2089
+ fn sin_cos ( self ) -> ( Self , Self ) {
2090
+ // Panics if self is +/-infinity
2091
+ let ( a, b) = self . 0 . sin_cos ( ) ;
2092
+ (
2093
+ NotNan :: new ( a) . expect ( "Sine resulted in NaN" ) ,
2094
+ NotNan :: new ( b) . expect ( "Cosine resulted in NaN" ) ,
2095
+ )
2096
+ }
2097
+ fn exp_m1 ( self ) -> Self {
2098
+ NotNan ( self . 0 . exp_m1 ( ) )
2099
+ }
2100
+ fn ln_1p ( self ) -> Self {
2101
+ // Panics if self <= -1.0
2102
+ NotNan :: new ( self . 0 . ln_1p ( ) ) . expect ( "Natural logarithm resulted in NaN" )
2103
+ }
2104
+ fn sinh ( self ) -> Self {
2105
+ NotNan ( self . 0 . sinh ( ) )
2106
+ }
2107
+ fn cosh ( self ) -> Self {
2108
+ NotNan ( self . 0 . cosh ( ) )
2109
+ }
2110
+ fn tanh ( self ) -> Self {
2111
+ NotNan ( self . 0 . tanh ( ) )
2112
+ }
2113
+ fn asinh ( self ) -> Self {
2114
+ NotNan ( self . 0 . asinh ( ) )
2115
+ }
2116
+ fn acosh ( self ) -> Self {
2117
+ // Panics if self < 1.0
2118
+ NotNan :: new ( self . 0 . acosh ( ) ) . expect ( "Arccosh resulted in NaN" )
2119
+ }
2120
+ fn atanh ( self ) -> Self {
2121
+ // Panics if self < -1.0 or self > 1.0
2122
+ NotNan :: new ( self . 0 . atanh ( ) ) . expect ( "Arctanh resulted in NaN" )
2123
+ }
2124
+ }
2125
+
1960
2126
macro_rules! impl_float_const_method {
1961
2127
( $wrapper: expr, $method: ident) => {
1962
2128
#[ allow( non_snake_case) ]
0 commit comments