Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:19:39

0001 // Copyright 2023 Matt Borland
0002 // Distributed under the Boost Software License, Version 1.0.
0003 // https://www.boost.org/LICENSE_1_0.txt
0004 
0005 #ifndef BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP
0006 #define BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP
0007 
0008 #include <boost/charconv/detail/compute_float64.hpp>
0009 #include <limits>
0010 #include <cstdint>
0011 #include <cmath>
0012 
0013 namespace boost { namespace charconv { namespace detail {
0014 
0015 inline float compute_float32(std::int64_t power, std::uint64_t i, bool negative, bool& success) noexcept
0016 {
0017     const double d = compute_float64(power, i, negative, success);
0018     float return_val;
0019 
0020     if (success)
0021     {
0022         // Some compilers (e.g. Intel) will optimize std::isinf to always false depending on compiler flags
0023         //
0024         // From Intel(R) oneAPI DPC++/C++ Compiler 2023.0.0 (2023.0.0.20221201)
0025         // warning: comparison with infinity always evaluates to false in fast floating point modes [-Wtautological-constant-compare]
0026         // if (std::isinf(return_val))
0027         if (d > static_cast<double>((std::numeric_limits<float>::max)()) ||
0028             d < static_cast<double>((std::numeric_limits<float>::lowest)()))
0029         {
0030             return_val = negative ? -HUGE_VALF : HUGE_VALF;
0031             success = false;
0032         }
0033         else
0034         {
0035             return_val = static_cast<float>(d);
0036         }
0037     }
0038     else
0039     {
0040         if (power > 38)
0041         {
0042             return_val = negative ? -HUGE_VALF : HUGE_VALF;
0043         }
0044         else
0045         {
0046             return_val = negative ? -0.0F : 0.0F;
0047         }
0048     }
0049 
0050     return return_val;
0051 }
0052 
0053 }}} // Namespaces
0054 
0055 #endif // BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP