Cubic root. This function is exact to rounding for all rounding modes. See also:** Documentation for [std::cbrt](https://en.cppreference.com/w/cpp/numeric/math/cbrt). \param arg function argument \return cubic root of \a arg \exception FE_INVALID for signaling NaN \exception FE_INEXACT according to rounding
| 3262 | /// \exception FE_INVALID for signaling NaN |
| 3263 | /// \exception FE_INEXACT according to rounding |
| 3264 | inline half cbrt(half arg) |
| 3265 | { |
| 3266 | #if defined(HALF_ARITHMETIC_TYPE) && HALF_ENABLE_CPP11_CMATH |
| 3267 | return half(detail::binary, detail::float2half<half::round_style>(std::cbrt(detail::half2float<detail::internal_t>(arg.data_)))); |
| 3268 | #else |
| 3269 | int abs = arg.data_ & 0x7FFF, exp = -15; |
| 3270 | if(!abs || abs == 0x3C00 || abs >= 0x7C00) |
| 3271 | return (abs>0x7C00) ? half(detail::binary, detail::signal(arg.data_)) : arg; |
| 3272 | for(; abs<0x400; abs<<=1, --exp); |
| 3273 | detail::uint32 ilog = exp + (abs>>10), sign = detail::sign_mask(ilog), f, m = |
| 3274 | (((ilog<<27)+(detail::log2(static_cast<detail::uint32>((abs&0x3FF)|0x400)<<20, 24)>>4))^sign) - sign; |
| 3275 | for(exp=2; m<0x80000000; m<<=1,--exp) ; |
| 3276 | m = detail::multiply64(m, 0xAAAAAAAB); |
| 3277 | int i = m >> 31, s; |
| 3278 | exp += i; |
| 3279 | m <<= 1 - i; |
| 3280 | if(exp < 0) |
| 3281 | { |
| 3282 | f = m >> -exp; |
| 3283 | exp = 0; |
| 3284 | } |
| 3285 | else |
| 3286 | { |
| 3287 | f = (m<<exp) & 0x7FFFFFFF; |
| 3288 | exp = m >> (31-exp); |
| 3289 | } |
| 3290 | m = detail::exp2(f, (half::round_style==std::round_to_nearest) ? 29 : 26); |
| 3291 | if(sign) |
| 3292 | { |
| 3293 | if(m > 0x80000000) |
| 3294 | { |
| 3295 | m = detail::divide64(0x80000000, m, s); |
| 3296 | ++exp; |
| 3297 | } |
| 3298 | exp = -exp; |
| 3299 | } |
| 3300 | return half(detail::binary, (half::round_style==std::round_to_nearest) ? |
| 3301 | detail::fixed2half<half::round_style,31,false,false,false>(m, exp+14, arg.data_&0x8000) : |
| 3302 | detail::fixed2half<half::round_style,23,false,false,false>((m+0x80)>>8, exp+14, arg.data_&0x8000)); |
| 3303 | #endif |
| 3304 | } |
| 3305 | |
| 3306 | /// Hypotenuse function. |
| 3307 | /// This function is exact to rounding for all rounding modes. |