Natural logarithm. This function is exact to rounding for all rounding modes. See also:** Documentation for [std::log](https://en.cppreference.com/w/cpp/numeric/math/log). \param arg function argument \return logarithm of \a arg to base e \exception FE_INVALID for signaling NaN or negative argument \exception FE_DIVBYZERO for 0 \exception FE_OVERFLOW, ...UNDERFLOW, ...INEXACT according to roundin
| 3059 | /// \exception FE_DIVBYZERO for 0 |
| 3060 | /// \exception FE_OVERFLOW, ...UNDERFLOW, ...INEXACT according to rounding |
| 3061 | inline half log(half arg) |
| 3062 | { |
| 3063 | #ifdef HALF_ARITHMETIC_TYPE |
| 3064 | return half(detail::binary, detail::float2half<half::round_style>(std::log(detail::half2float<detail::internal_t>(arg.data_)))); |
| 3065 | #else |
| 3066 | int abs = arg.data_ & 0x7FFF, exp = -15; |
| 3067 | if(!abs) |
| 3068 | return half(detail::binary, detail::pole(0x8000)); |
| 3069 | if(arg.data_ & 0x8000) |
| 3070 | return half(detail::binary, (arg.data_<=0xFC00) ? detail::invalid() : detail::signal(arg.data_)); |
| 3071 | if(abs >= 0x7C00) |
| 3072 | return (abs==0x7C00) ? arg : half(detail::binary, detail::signal(arg.data_)); |
| 3073 | for(; abs<0x400; abs<<=1,--exp) ; |
| 3074 | exp += abs >> 10; |
| 3075 | return half(detail::binary, detail::log2_post<half::round_style,0xB8AA3B2A>( |
| 3076 | detail::log2(static_cast<detail::uint32>((abs&0x3FF)|0x400)<<20, 27)+8, exp, 17)); |
| 3077 | #endif |
| 3078 | } |
| 3079 | |
| 3080 | /// Common logarithm. |
| 3081 | /// This function is exact to rounding for all rounding modes. |