MCPcopy Create free account
hub / github.com/apache/singa / expm1

Function expm1

include/half.hpp:3007–3050  ·  view source on GitHub ↗

Exponential minus one. This function may be 1 ULP off the correctly rounded exact result in <0.05% of inputs for `std::round_to_nearest` and in <1% of inputs for any other rounding mode. See also:** Documentation for [std::expm1](https://en.cppreference.com/w/cpp/numeric/math/expm1). \param arg function argument \return e raised to \a arg and subtracted by 1 \exception FE_INVALID for signaling Na

Source from the content-addressed store, hash-verified

3005 /// \exception FE_INVALID for signaling NaN
3006 /// \exception FE_OVERFLOW, ...UNDERFLOW, ...INEXACT according to rounding
3007 inline half expm1(half arg)
3008 {
3009 #if defined(HALF_ARITHMETIC_TYPE) && HALF_ENABLE_CPP11_CMATH
3010 return half(detail::binary, detail::float2half<half::round_style>(std::expm1(detail::half2float<detail::internal_t>(arg.data_))));
3011 #else
3012 unsigned int abs = arg.data_ & 0x7FFF, sign = arg.data_ & 0x8000;
3013 if(!abs)
3014 return arg;
3015 if(abs >= 0x7C00)
3016 return half(detail::binary, (abs==0x7C00) ? (0x7C00+(sign>>1)) : detail::signal(arg.data_));
3017 if(abs >= 0x4A00)
3018 return half(detail::binary, (arg.data_&0x8000) ? detail::rounded<half::round_style,true>(0xBBFF, 1, 1) : detail::overflow<half::round_style>());
3019 detail::uint32 m = detail::multiply64(static_cast<detail::uint32>((abs&0x3FF)+((abs>0x3FF)<<10))<<21, 0xB8AA3B29);
3020 int e = (abs>>10) + (abs<=0x3FF), exp;
3021 if(e < 14)
3022 {
3023 exp = 0;
3024 m >>= 14 - e;
3025 }
3026 else
3027 {
3028 exp = m >> (45-e);
3029 m = (m<<(e-14)) & 0x7FFFFFFF;
3030 }
3031 m = detail::exp2(m);
3032 if(sign)
3033 {
3034 int s = 0;
3035 if(m > 0x80000000)
3036 {
3037 ++exp;
3038 m = detail::divide64(0x80000000, m, s);
3039 }
3040 m = 0x80000000 - ((m>>exp)|((m&((static_cast<detail::uint32>(1)<<exp)-1))!=0)|s);
3041 exp = 0;
3042 }
3043 else
3044 m -= (exp<31) ? (0x80000000>>exp) : 1;
3045 for(exp+=14; m<0x80000000 && exp; m<<=1,--exp) ;
3046 if(exp > 29)
3047 return half(detail::binary, detail::overflow<half::round_style>());
3048 return half(detail::binary, detail::rounded<half::round_style,true>(sign+(exp<<10)+(m>>21), (m>>20)&1, (m&0xFFFFF)!=0));
3049 #endif
3050 }
3051
3052 /// Natural logarithm.
3053 /// This function is exact to rounding for all rounding modes.

Callers

nothing calls this directly

Calls 5

halfClass · 0.85
signalFunction · 0.85
multiply64Function · 0.85
exp2Function · 0.85
divide64Function · 0.85

Tested by

no test coverage detected