@@ -617,9 +617,6 @@ constexpr bool isWithin (Type a, Type b, Type tolerance) noexcept
617617// ==============================================================================
618618#if YUP_MSVC
619619#pragma optimize("t", off)
620- #ifndef __INTEL_COMPILER
621- #pragma float_control(precise, on, push)
622- #endif
623620#endif
624621
625622/* * Fast floating-point-to-integer conversion.
@@ -633,36 +630,36 @@ constexpr bool isWithin (Type a, Type b, Type tolerance) noexcept
633630 even numbers will be rounded up or down differently.
634631*/
635632template <typename FloatType>
636- int roundToInt (const FloatType value) noexcept
633+ constexpr int roundToInt (const FloatType value) noexcept
637634{
638- # ifdef __INTEL_COMPILER
639- # pragma float_control(precise, on, push)
640- # endif
641-
642- union
635+ if ( isConstantEvaluated ())
636+ {
637+ return static_cast < int > (value > FloatType ( 0 ) ? value + FloatType ( 0.5 ) : value - FloatType ( 0.5 ));
638+ }
639+ else
643640 {
644- int asInt[2 ];
645- double asDouble;
646- } n;
641+ union
642+ {
643+ int asInt[2 ];
644+ double asDouble;
645+ } n;
647646
648- n.asDouble = ((double ) value) + 6755399441055744.0 ;
647+ n.asDouble = ((double ) value) + 6755399441055744.0 ;
649648
650649#if YUP_BIG_ENDIAN
651- return n.asInt [1 ];
650+ return n.asInt [1 ];
652651#else
653- return n.asInt [0 ];
652+ return n.asInt [0 ];
654653#endif
654+ }
655655}
656656
657- inline int roundToInt (int value) noexcept
657+ constexpr int roundToInt (int value) noexcept
658658{
659659 return value;
660660}
661661
662662#if YUP_MSVC
663- #ifndef __INTEL_COMPILER
664- #pragma float_control(pop)
665- #endif
666663#pragma optimize("", on) // resets optimisations to the project defaults
667664#endif
668665
@@ -671,12 +668,8 @@ inline int roundToInt (int value) noexcept
671668 This is a slightly slower and slightly more accurate version of roundToInt(). It works
672669 fine for values above zero, but negative numbers are rounded the wrong way.
673670*/
674- inline int roundToIntAccurate (double value) noexcept
671+ constexpr int roundToIntAccurate (double value) noexcept
675672{
676- #ifdef __INTEL_COMPILER
677- #pragma float_control(pop)
678- #endif
679-
680673 return roundToInt (value + 1.5e-8 );
681674}
682675
0 commit comments