MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / round

Function round

modules/engine/runtime/include/SkrRT/misc/fast_float.h:2544–2570  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2542// round an extended-precision float to the nearest machine float.
2543template <typename T, typename callback>
2544fastfloat_really_inline void round(adjusted_mantissa& am, callback cb) noexcept {
2545 int32_t mantissa_shift = 64 - binary_format<T>::mantissa_explicit_bits() - 1;
2546 if (-am.power2 >= mantissa_shift) {
2547 // have a denormal float
2548 int32_t shift = -am.power2 + 1;
2549 cb(am, std::min(shift, 64));
2550 // check for round-up: if rounding-nearest carried us to the hidden bit.
2551 am.power2 = (am.mantissa < (uint64_t(1) << binary_format<T>::mantissa_explicit_bits())) ? 0 : 1;
2552 return;
2553 }
2554
2555 // have a normal float, use the default shift.
2556 cb(am, mantissa_shift);
2557
2558 // check for carry
2559 if (am.mantissa >= (uint64_t(2) << binary_format<T>::mantissa_explicit_bits())) {
2560 am.mantissa = (uint64_t(1) << binary_format<T>::mantissa_explicit_bits());
2561 am.power2++;
2562 }
2563
2564 // check for infinite: we could have carried to an infinite power
2565 am.mantissa &= ~(uint64_t(1) << binary_format<T>::mantissa_explicit_bits());
2566 if (am.power2 >= binary_format<T>::infinite_power()) {
2567 am.power2 = binary_format<T>::infinite_power();
2568 am.mantissa = 0;
2569 }
2570}
2571
2572template <typename callback>
2573fastfloat_really_inline

Callers 9

skr_sys_get_timeFunction · 0.50
skr_sys_get_timeFunction · 0.50
roundMethod · 0.50
get_hex_code_box_sizeMethod · 0.50
draw_hex_code_boxMethod · 0.50
_shape_substrMethod · 0.50
_shape_single_glyphMethod · 0.50

Calls 1

minFunction · 0.50

Tested by

no test coverage detected