ReactOS 0.4.16-dev-716-g2b2bdab
__crt_strtox Namespace Reference

Classes

struct  big_integer
 
class  c_string_character_source
 
struct  floating_point_string
 
class  floating_point_value
 
class  input_adapter_character_source
 
struct  is_signed
 
struct  is_signed< long >
 
struct  is_signed< long long >
 
struct  is_signed< unsigned long >
 
struct  is_signed< unsigned long long >
 
struct  make_signed
 
struct  make_signed< long >
 
struct  make_signed< long long >
 
struct  make_signed< unsigned long >
 
struct  make_signed< unsigned long long >
 
struct  make_unsigned
 
struct  make_unsigned< long >
 
struct  make_unsigned< long long >
 
struct  make_unsigned< unsigned long >
 
struct  make_unsigned< unsigned long long >
 

Enumerations

enum  : unsigned { FL_SIGNED = 0x01 , FL_NEGATIVE = 0x02 , FL_OVERFLOW = 0x04 , FL_READ_DIGIT = 0x08 }
 
enum class  floating_point_parse_result {
  decimal_digits , hexadecimal_digits , zero , infinity ,
  qnan , snan , indeterminate , no_digits ,
  underflow , overflow
}
 
enum  { maximum_temporary_decimal_exponent = 5200 , minimum_temporary_decimal_exponent = -5200 }
 

Functions

void __cdecl assemble_floating_point_zero (bool const is_negative, _LDBL12 &result) throw ()
 
void __cdecl assemble_floating_point_infinity (bool const is_negative, _LDBL12 &result) throw ()
 
void __cdecl assemble_floating_point_qnan (bool const is_negative, _LDBL12 &result) throw ()
 
void __cdecl assemble_floating_point_snan (bool const is_negative, _LDBL12 &result) throw ()
 
void __cdecl assemble_floating_point_ind (_LDBL12 &result) throw ()
 
static SLD_STATUS __cdecl common_convert_to_ldbl12 (floating_point_string const &immutable_data, bool const is_hexadecimal, _LDBL12 &result) throw ()
 
SLD_STATUS __cdecl convert_decimal_string_to_floating_type (floating_point_string const &data, _LDBL12 &result) throw ()
 
SLD_STATUS __cdecl convert_hexadecimal_string_to_floating_type (floating_point_string const &data, _LDBL12 &result) throw ()
 
__forceinline bool __cdecl operator== (big_integer const &lhs, big_integer const &rhs) throw ()
 
__forceinline bool __cdecl operator!= (big_integer const &lhs, big_integer const &rhs) throw ()
 
__forceinline bool __cdecl operator< (big_integer const &lhs, big_integer const &rhs) throw ()
 
__forceinline bool __cdecl operator>= (big_integer const &lhs, big_integer const &rhs) throw ()
 
__forceinline big_integer __cdecl make_big_integer (uint64_t const value) throw ()
 
__forceinline big_integer __cdecl make_big_integer_power_of_two (uint32_t const power) throw ()
 
__forceinline bool __cdecl is_zero (big_integer const &value) throw ()
 
__forceinline uint32_t __cdecl bit_scan_reverse (uint32_t const value) throw ()
 
__forceinline uint32_t __cdecl bit_scan_reverse (uint64_t const value) throw ()
 
__forceinline uint32_t __cdecl bit_scan_reverse (big_integer const &x) throw ()
 
__forceinline bool __cdecl shift_left (big_integer &x, uint32_t const n) throw ()
 
__forceinline bool __cdecl add (big_integer &x, uint32_t const value) throw ()
 
__forceinline uint32_t __cdecl add_carry (uint32_t &u1, uint32_t const u2, uint32_t const u_carry) throw ()
 
__forceinline uint32_t __cdecl add_multiply_carry (uint32_t &u_add, uint32_t const u_mul_1, uint32_t const u_mul_2, uint32_t const u_carry) throw ()
 
__forceinline uint32_t __cdecl multiply_core (_Inout_updates_all_(multiplicand_count) uint32_t *const multiplicand, uint32_t const multiplicand_count, uint32_t const multiplier) throw ()
 
__forceinline bool __cdecl multiply (big_integer &multiplicand, uint32_t const multiplier) throw ()
 
__forceinline bool __cdecl multiply (big_integer &multiplicand, big_integer const &multiplier) throw ()
 
__forceinline bool __cdecl multiply_by_power_of_ten (big_integer &x, uint32_t const power) throw ()
 
__forceinline uint32_t __cdecl count_sequential_high_zeroes (uint32_t const u) throw ()
 
__forceinline uint64_t __cdecl multiply_64_32 (uint64_t const multiplicand, uint32_t const multiplier) throw ()
 
uint64_t __cdecl divide (big_integer &numerator, big_integer const &denominator) throw ()
 
__forceinline int __cdecl wide_character_to_digit (wchar_t const c) throw ()
 
__forceinline unsigned __cdecl parse_digit (char const c) throw ()
 
__forceinline unsigned __cdecl parse_digit (wchar_t const c) throw ()
 
__forceinline bool __cdecl is_digit_or_nondigit (int const c) throw ()
 
__forceinline bool __cdecl is_space (char const c, _locale_t const locale) throw ()
 
__forceinline bool __cdecl is_space (wchar_t const c, _locale_t) throw ()
 
long minimum_signed_value (unsigned long) throw ()
 
long maximum_signed_value (unsigned long) throw ()
 
__int64 minimum_signed_value (unsigned __int64) throw ()
 
__int64 maximum_signed_value (unsigned __int64) throw ()
 
template<typename UnsignedInteger >
bool is_overflow_condition (unsigned const flags, UnsignedInteger const number) throw ()
 
template<typename UnsignedInteger , typename CharacterSource , bool TrimWhitespace = true>
UnsignedInteger __cdecl parse_integer (__crt_cached_ptd_host &ptd, CharacterSource source, int base, bool const is_result_signed) throw ()
 
template<typename UnsignedInteger , typename CharacterSource >
UnsignedInteger __cdecl parse_integer (_locale_t const locale, CharacterSource source, int base, bool const is_result_signed) throw ()
 
template<typename FloatingType >
void __cdecl assemble_floating_point_zero (bool const is_negative, FloatingType &result) throw ()
 
void __cdecl assemble_floating_point_zero (bool const is_negative, floating_point_value const &result) throw ()
 
template<typename FloatingType >
void __cdecl assemble_floating_point_infinity (bool const is_negative, FloatingType &result) throw ()
 
void __cdecl assemble_floating_point_infinity (bool const is_negative, floating_point_value const &result) throw ()
 
template<typename FloatingType >
void __cdecl assemble_floating_point_qnan (bool const is_negative, FloatingType &result) throw ()
 
void __cdecl assemble_floating_point_qnan (bool const is_negative, floating_point_value const &result) throw ()
 
template<typename FloatingType >
void __cdecl assemble_floating_point_snan (bool const is_negative, FloatingType &result) throw ()
 
void __cdecl assemble_floating_point_snan (bool const is_negative, floating_point_value const &result) throw ()
 
template<typename FloatingType >
void __cdecl assemble_floating_point_ind (FloatingType &result) throw ()
 
void __cdecl assemble_floating_point_ind (floating_point_value const &result) throw ()
 
__forceinline bool __cdecl should_round_up (bool const is_negative, bool const lsb_bit, bool const round_bit, bool const has_tail_bits) throw ()
 
__forceinline uint64_t __cdecl right_shift_with_rounding (bool const is_negative, uint64_t const value, uint32_t const shift, bool const has_zero_tail) throw ()
 
template<typename FloatingType >
SLD_STATUS __cdecl assemble_floating_point_value_t (bool const is_negative, int32_t const exponent, uint64_t const mantissa, FloatingType &result) throw ()
 
SLD_STATUS __cdecl assemble_floating_point_value (uint64_t const initial_mantissa, int32_t const initial_exponent, bool const is_negative, bool const has_zero_tail, floating_point_value const &result) throw ()
 
SLD_STATUS __cdecl assemble_floating_point_value_from_big_integer (big_integer const &integer_value, uint32_t const integer_bits_of_precision, bool const is_negative, bool const has_nonzero_fractional_part, floating_point_value const &result) throw ()
 
__forceinline void __cdecl accumulate_decimal_digits_into_big_integer (uint8_t const *const first_digit, uint8_t const *const last_digit, big_integer &result) throw ()
 
SLD_STATUS __cdecl convert_decimal_string_to_floating_type_common (floating_point_string const &data, floating_point_value const &result) throw ()
 
template<typename FloatingType >
SLD_STATUS __cdecl convert_decimal_string_to_floating_type (floating_point_string const &data, FloatingType &result) throw ()
 
SLD_STATUS __cdecl convert_hexadecimal_string_to_floating_type_common (floating_point_string const &data, floating_point_value const &result) throw ()
 
template<typename FloatingType >
SLD_STATUS __cdecl convert_hexadecimal_string_to_floating_type (floating_point_string const &data, FloatingType &result) throw ()
 
template<typename Character , typename CharacterSource >
bool __cdecl parse_next_characters_from_source (Character const *const uppercase, Character const *const lowercase, size_t const count, Character &c, CharacterSource &source) throw ()
 
template<typename Character , typename CharacterSource >
bool __cdecl parse_floating_point_possible_nan_is_snan (Character &c, CharacterSource &source) throw ()
 
template<typename Character , typename CharacterSource >
bool __cdecl parse_floating_point_possible_nan_is_ind (Character &c, CharacterSource &source) throw ()
 
template<typename Character , typename CharacterSource , typename StoredState >
floating_point_parse_result __cdecl parse_floating_point_possible_infinity (Character &c, CharacterSource &source, StoredState stored_state) throw ()
 
template<typename Character , typename CharacterSource , typename StoredState >
floating_point_parse_result __cdecl parse_floating_point_possible_nan (Character &c, CharacterSource &source, StoredState stored_state) throw ()
 
template<typename CharacterSource >
floating_point_parse_result __cdecl parse_floating_point_from_source (_locale_t const locale, CharacterSource &source, floating_point_string &fp_string) throw ()
 
template<typename FloatingType >
SLD_STATUS __cdecl parse_floating_point_write_result (floating_point_parse_result const parse_result, floating_point_string const &fp_string, FloatingType *const result) throw ()
 
template<typename CharacterSource , typename FloatingType >
SLD_STATUS __cdecl parse_floating_point (_locale_t const locale, CharacterSource source, FloatingType *const result) throw ()
 
template<typename Character , typename EndPointer >
c_string_character_source< Character > __cdecl make_c_string_character_source (Character const *const string, EndPointer const end) throw ()
 
template<typename Integer , typename Character , typename EndPointer >
__forceinline Integer __cdecl parse_integer_from_string (Character const *const string, EndPointer const end, int const base, _locale_t const locale) throw ()
 
template<typename InputAdapter >
input_adapter_character_source< InputAdapter > __cdecl make_input_adapter_character_source (InputAdapter *const input_adapter, uint64_t const width, bool *const succeeded) throw ()
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : unsigned
Enumerator
FL_SIGNED 
FL_NEGATIVE 
FL_OVERFLOW 
FL_READ_DIGIT 

Definition at line 196 of file corecrt_internal_strtox.h.

197{
198 FL_SIGNED = 0x01,
199 FL_NEGATIVE = 0x02,
200 FL_OVERFLOW = 0x04,
201 FL_READ_DIGIT = 0x08
202};

◆ anonymous enum

anonymous enum
Enumerator
maximum_temporary_decimal_exponent 
minimum_temporary_decimal_exponent 

Definition at line 410 of file corecrt_internal_strtox.h.

◆ floating_point_parse_result

Function Documentation

◆ accumulate_decimal_digits_into_big_integer()

__forceinline void __cdecl __crt_strtox::accumulate_decimal_digits_into_big_integer ( uint8_t const *const  first_digit,
uint8_t const *const  last_digit,
big_integer result 
)
throw (
)

Definition at line 953 of file corecrt_internal_strtox.h.

958{
959 // We accumulate nine digit chunks, transforming the base ten string into
960 // base one billion on the fly, allowing us to reduce the number of high
961 // precision multiplication and addition operations by 8/9.
962 uint32_t accumulator{};
963 uint32_t accumulator_count{};
964 for (uint8_t const* it = first_digit; it != last_digit; ++it)
965 {
966 if (accumulator_count == 9)
967 {
968 multiply(result, 1000 * 1000 * 1000);
969 add(result, accumulator);
970
971 accumulator = 0;
972 accumulator_count = 0;
973 }
974
975 accumulator *= 10;
976 accumulator += *it;
977 ++accumulator_count;
978 }
979
980 if (accumulator_count != 0)
981 {
982 multiply_by_power_of_ten(result, accumulator_count);
983 add(result, accumulator);
984 }
985}
UINT32 uint32_t
Definition: types.h:75
GLuint64EXT * result
Definition: glext.h:11304
BYTE uint8_t
Definition: msvideo1.c:66
__forceinline bool __cdecl add(big_integer &x, uint32_t const value)
__forceinline bool __cdecl multiply(big_integer &multiplicand, uint32_t const multiplier)
__forceinline bool __cdecl multiply_by_power_of_ten(big_integer &x, uint32_t const power)

Referenced by convert_decimal_string_to_floating_type_common().

◆ add()

__forceinline bool __cdecl __crt_strtox::add ( big_integer x,
uint32_t const  value 
)
throw (
)

Definition at line 256 of file corecrt_internal_big_integer.h.

257{
258 if (value == 0)
259 {
260 return true;
261 }
262
263 uint32_t carry = value;
264 for (uint32_t i = 0; i != x._used; ++i)
265 {
266 uint64_t const result = static_cast<uint64_t>(x._data[i]) + carry;
267 x._data[i] = static_cast<uint32_t>(result);
268 carry = static_cast<uint32_t>(result >> 32);
269 }
270
271 if (carry != 0)
272 {
273 if (x._used < big_integer::element_count)
274 {
275 x._data[x._used] = carry;
276 ++x._used;
277 }
278 else
279 {
280 x = big_integer{};
281 return false;
282 }
283 }
284
285 return true;
286}
UINT64 uint64_t
Definition: types.h:77
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: pdh_main.c:94

Referenced by accumulate_decimal_digits_into_big_integer().

◆ add_carry()

__forceinline uint32_t __cdecl __crt_strtox::add_carry ( uint32_t u1,
uint32_t const  u2,
uint32_t const  u_carry 
)
throw (
)

Definition at line 288 of file corecrt_internal_big_integer.h.

293{
294 uint64_t const uu = static_cast<uint64_t>(u1) + u2 + u_carry;
295 u1 = static_cast<uint32_t>(uu);
296 return static_cast<uint32_t>(uu >> 32);
297}
GLdouble GLdouble u2
Definition: glext.h:8308
GLdouble u1
Definition: glext.h:8308

Referenced by multiply().

◆ add_multiply_carry()

__forceinline uint32_t __cdecl __crt_strtox::add_multiply_carry ( uint32_t u_add,
uint32_t const  u_mul_1,
uint32_t const  u_mul_2,
uint32_t const  u_carry 
)
throw (
)

Definition at line 299 of file corecrt_internal_big_integer.h.

305{
306 uint64_t const uu_res = static_cast<uint64_t>(u_mul_1) * u_mul_2 + u_add + u_carry;
307 u_add = static_cast<uint32_t>(uu_res);
308 return reinterpret_cast<unsigned const*>(&uu_res)[1];
309}
#define const
Definition: zconf.h:233

Referenced by multiply().

◆ assemble_floating_point_ind() [1/3]

void __cdecl __crt_strtox::assemble_floating_point_ind ( _LDBL12 result)
throw (
)

Definition at line 582 of file atoldbl.cpp.

583{
584 uint16_t const sign_bit{static_cast<uint16_t>(MSB_USHORT)};
585
586 *U_XT_12 (&result) = 0x0000;
587 *UL_MANLO_12(&result) = 0x00000000;
588 *UL_MANHI_12(&result) = 0xc0000000;
589 *U_EXP_12 (&result) = static_cast<uint16_t>(LD_MAXEXP) | sign_bit;
590}
unsigned short int uint16_t
Definition: acefiex.h:54
#define U_EXP_12(p)
Definition: atoldbl.cpp:51
#define UL_MANHI_12(p)
Definition: atoldbl.cpp:52
#define LD_MAXEXP
Definition: atoldbl.cpp:34
#define U_XT_12(p)
Definition: atoldbl.cpp:54
#define MSB_USHORT
Definition: atoldbl.cpp:23
#define UL_MANLO_12(p)
Definition: atoldbl.cpp:53

Referenced by assemble_floating_point_ind(), and parse_floating_point_write_result().

◆ assemble_floating_point_ind() [2/3]

void __cdecl __crt_strtox::assemble_floating_point_ind ( floating_point_value const result)
throw (
)
inline

Definition at line 615 of file corecrt_internal_strtox.h.

616{
617 if (result.is_double())
618 {
620 }
621 else
622 {
623 assemble_floating_point_ind(result.as_float());
624 }
625}
void __cdecl assemble_floating_point_ind(_LDBL12 &result)
Definition: atoldbl.cpp:582

◆ assemble_floating_point_ind() [3/3]

template<typename FloatingType >
void __cdecl __crt_strtox::assemble_floating_point_ind ( FloatingType &  result)
throw (
)

Definition at line 604 of file corecrt_internal_strtox.h.

605{
606 using floating_traits = __acrt_floating_type_traits<FloatingType>;
607 using components_type = typename floating_traits::components_type;
608
609 components_type& result_components = reinterpret_cast<components_type&>(result);
610 result_components._sign = 1;
611 result_components._exponent = floating_traits::exponent_mask;
612 result_components._mantissa = floating_traits::special_nan_mantissa_mask;
613}
floating_traits::components_type components_type
Definition: cvt.cpp:357

◆ assemble_floating_point_infinity() [1/3]

void __cdecl __crt_strtox::assemble_floating_point_infinity ( bool const  is_negative,
_LDBL12 result 
)
throw (
)

Definition at line 551 of file atoldbl.cpp.

552{
553 uint16_t const sign_bit{static_cast<uint16_t>(is_negative ? MSB_USHORT : 0x0000)};
554
555 // Infinity has an all-zero mantissa and an all-one exponent
556 *U_XT_12 (&result) = 0;
557 *UL_MANLO_12(&result) = 0;
558 *UL_MANHI_12(&result) = 0;
559 *U_EXP_12 (&result) = static_cast<uint16_t>(LD_MAXEXP) | sign_bit;
560}

Referenced by assemble_floating_point_infinity(), assemble_floating_point_value(), convert_decimal_string_to_floating_type_common(), and parse_floating_point_write_result().

◆ assemble_floating_point_infinity() [2/3]

void __cdecl __crt_strtox::assemble_floating_point_infinity ( bool const  is_negative,
floating_point_value const result 
)
throw (
)
inline

Definition at line 540 of file corecrt_internal_strtox.h.

541{
542 if (result.is_double())
543 {
544 assemble_floating_point_infinity(is_negative, result.as_double());
545 }
546 else
547 {
548 assemble_floating_point_infinity(is_negative, result.as_float());
549 }
550}
void __cdecl assemble_floating_point_infinity(bool const is_negative, _LDBL12 &result)
Definition: atoldbl.cpp:551

◆ assemble_floating_point_infinity() [3/3]

template<typename FloatingType >
void __cdecl __crt_strtox::assemble_floating_point_infinity ( bool const  is_negative,
FloatingType &  result 
)
throw (
)

Definition at line 529 of file corecrt_internal_strtox.h.

530{
531 using floating_traits = __acrt_floating_type_traits<FloatingType>;
532 using components_type = typename floating_traits::components_type;
533
534 components_type& result_components = reinterpret_cast<components_type&>(result);
535 result_components._sign = is_negative ? 1 : 0;
536 result_components._exponent = floating_traits::exponent_mask;
537 result_components._mantissa = 0;
538}

◆ assemble_floating_point_qnan() [1/3]

void __cdecl __crt_strtox::assemble_floating_point_qnan ( bool const  is_negative,
_LDBL12 result 
)
throw (
)

Definition at line 562 of file atoldbl.cpp.

563{
564 uint16_t const sign_bit{static_cast<uint16_t>(is_negative ? MSB_USHORT : 0x0000)};
565
566 *U_XT_12 (&result) = 0xffff;
567 *UL_MANLO_12(&result) = 0xffffffff;
568 *UL_MANHI_12(&result) = 0xffffffff;
569 *U_EXP_12 (&result) = static_cast<uint16_t>(LD_MAXEXP) | sign_bit;
570}

Referenced by assemble_floating_point_qnan(), and parse_floating_point_write_result().

◆ assemble_floating_point_qnan() [2/3]

void __cdecl __crt_strtox::assemble_floating_point_qnan ( bool const  is_negative,
floating_point_value const result 
)
throw (
)
inline

Definition at line 565 of file corecrt_internal_strtox.h.

566{
567 if (result.is_double())
568 {
569 assemble_floating_point_qnan(is_negative, result.as_double());
570 }
571 else
572 {
573 assemble_floating_point_qnan(is_negative, result.as_float());
574 }
575}
void __cdecl assemble_floating_point_qnan(bool const is_negative, _LDBL12 &result)
Definition: atoldbl.cpp:562

◆ assemble_floating_point_qnan() [3/3]

template<typename FloatingType >
void __cdecl __crt_strtox::assemble_floating_point_qnan ( bool const  is_negative,
FloatingType &  result 
)
throw (
)

Definition at line 554 of file corecrt_internal_strtox.h.

555{
556 using floating_traits = __acrt_floating_type_traits<FloatingType>;
557 using components_type = typename floating_traits::components_type;
558
559 components_type& result_components = reinterpret_cast<components_type&>(result);
560 result_components._sign = is_negative ? 1 : 0;
561 result_components._exponent = floating_traits::exponent_mask;
562 result_components._mantissa = floating_traits::denormal_mantissa_mask;
563}

◆ assemble_floating_point_snan() [1/3]

void __cdecl __crt_strtox::assemble_floating_point_snan ( bool const  is_negative,
_LDBL12 result 
)
throw (
)

Definition at line 572 of file atoldbl.cpp.

573{
574 uint16_t const sign_bit{static_cast<uint16_t>(is_negative ? MSB_USHORT : 0x0000)};
575
576 *U_XT_12 (&result) = 0xffff;
577 *UL_MANLO_12(&result) = 0xffffffff;
578 *UL_MANHI_12(&result) = 0xbfffffff;
579 *U_EXP_12 (&result) = static_cast<uint16_t>(LD_MAXEXP) | sign_bit;
580}

Referenced by assemble_floating_point_snan(), and parse_floating_point_write_result().

◆ assemble_floating_point_snan() [2/3]

void __cdecl __crt_strtox::assemble_floating_point_snan ( bool const  is_negative,
floating_point_value const result 
)
throw (
)
inline

Definition at line 590 of file corecrt_internal_strtox.h.

591{
592 if (result.is_double())
593 {
594 assemble_floating_point_snan(is_negative, result.as_double());
595 }
596 else
597 {
598 assemble_floating_point_snan(is_negative, result.as_float());
599 }
600}
void __cdecl assemble_floating_point_snan(bool const is_negative, _LDBL12 &result)
Definition: atoldbl.cpp:572

◆ assemble_floating_point_snan() [3/3]

template<typename FloatingType >
void __cdecl __crt_strtox::assemble_floating_point_snan ( bool const  is_negative,
FloatingType &  result 
)
throw (
)

Definition at line 579 of file corecrt_internal_strtox.h.

580{
581 using floating_traits = __acrt_floating_type_traits<FloatingType>;
582 using components_type = typename floating_traits::components_type;
583
584 components_type& result_components = reinterpret_cast<components_type&>(result);
585 result_components._sign = is_negative ? 1 : 0;
586 result_components._exponent = floating_traits::exponent_mask;
587 result_components._mantissa = 1;
588}

◆ assemble_floating_point_value()

SLD_STATUS __cdecl __crt_strtox::assemble_floating_point_value ( uint64_t const  initial_mantissa,
int32_t const  initial_exponent,
bool const  is_negative,
bool const  has_zero_tail,
floating_point_value const result 
)
throw (
)
inline

Definition at line 735 of file corecrt_internal_strtox.h.

742{
743 // Assume that the number is representable as a normal value. Compute the
744 // number of bits by which we must adjust the mantissa to shift it into the
745 // correct position, and compute the resulting base two exponent for the
746 // normalized mantissa:
747 uint32_t const initial_mantissa_bits = bit_scan_reverse(initial_mantissa);
748 int32_t const normal_mantissa_shift = static_cast<int32_t>(result.mantissa_bits() - initial_mantissa_bits);
749 int32_t const normal_exponent = initial_exponent - normal_mantissa_shift;
750
751 uint64_t mantissa = initial_mantissa;
752 int32_t exponent = normal_exponent;
753
754 if (normal_exponent > result.maximum_binary_exponent())
755 {
756 // The exponent is too large to be represented by the floating point
757 // type; report the overflow condition:
759 return SLD_OVERFLOW;
760 }
761 else if (normal_exponent < result.minimum_binary_exponent())
762 {
763 // The exponent is too small to be represented by the floating point
764 // type as a normal value, but it may be representable as a denormal
765 // value. Compute the number of bits by which we need to shift the
766 // mantissa in order to form a denormal number. (The subtraction of
767 // an extra 1 is to account for the hidden bit of the mantissa that
768 // is not available for use when representing a denormal.)
769 int32_t const denormal_mantissa_shift =
770 normal_mantissa_shift +
771 normal_exponent +
772 result.exponent_bias() -
773 1;
774
775 // Denormal values have an exponent of zero, so the debiased exponent is
776 // the negation of the exponent bias:
777 exponent = -result.exponent_bias();
778
779 if (denormal_mantissa_shift < 0)
780 {
781 // Use two steps for right shifts: for a shift of N bits, we first
782 // shift by N-1 bits, then shift the last bit and use its value to
783 // round the mantissa.
784 mantissa = right_shift_with_rounding(is_negative, mantissa, -denormal_mantissa_shift, has_zero_tail);
785
786 // If the mantissa is now zero, we have underflowed:
787 if (mantissa == 0)
788 {
789 assemble_floating_point_zero(is_negative, result);
790 return SLD_UNDERFLOW;
791 }
792
793 // When we round the mantissa, the result may be so large that the
794 // number becomes a normal value. For example, consider the single
795 // precision case where the mantissa is 0x01ffffff and a right shift
796 // of 2 is required to shift the value into position. We perform the
797 // shift in two steps: we shift by one bit, then we shift again and
798 // round using the dropped bit. The initial shift yields 0x00ffffff.
799 // The rounding shift then yields 0x007fffff and because the least
800 // significant bit was 1, we add 1 to this number to round it. The
801 // final result is 0x00800000.
802 //
803 // 0x00800000 is 24 bits, which is more than the 23 bits available
804 // in the mantissa. Thus, we have rounded our denormal number into
805 // a normal number.
806 //
807 // We detect this case here and re-adjust the mantissa and exponent
808 // appropriately, to form a normal number:
809 if (mantissa > result.denormal_mantissa_mask())
810 {
811 // We add one to the denormal_mantissa_shift to account for the
812 // hidden mantissa bit (we subtracted one to account for this bit
813 // when we computed the denormal_mantissa_shift above).
814 exponent =
815 initial_exponent -
816 (denormal_mantissa_shift + 1) -
817 normal_mantissa_shift;
818 }
819 }
820 else
821 {
822 mantissa <<= denormal_mantissa_shift;
823 }
824 }
825 else
826 {
827 if (normal_mantissa_shift < 0)
828 {
829 // Use two steps for right shifts: for a shift of N bits, we first
830 // shift by N-1 bits, then shift the last bit and use its value to
831 // round the mantissa.
832 mantissa = right_shift_with_rounding(is_negative, mantissa, -normal_mantissa_shift, has_zero_tail);
833
834 // When we round the mantissa, it may produce a result that is too
835 // large. In this case, we divide the mantissa by two and increment
836 // the exponent (this does not change the value).
837 if (mantissa > result.normal_mantissa_mask())
838 {
839 mantissa >>= 1;
840 ++exponent;
841
842 // The increment of the exponent may have generated a value too
843 // large to be represented. In this case, report the overflow:
844 if (exponent > result.maximum_binary_exponent())
845 {
847 return SLD_OVERFLOW;
848 }
849 }
850 }
851 else if (normal_mantissa_shift > 0)
852 {
853 mantissa <<= normal_mantissa_shift;
854 }
855 }
856
857 // Unset the hidden bit in the mantissa and assemble the floating point value
858 // from the computed components:
859 mantissa &= result.denormal_mantissa_mask();
860
861 return result.is_double()
862 ? assemble_floating_point_value_t(is_negative, exponent, mantissa, result.as_double())
863 : assemble_floating_point_value_t(is_negative, exponent, mantissa, result.as_float());
864}
__int64 exponent
Definition: cvt.cpp:529
INT32 int32_t
Definition: types.h:71
__forceinline uint32_t __cdecl bit_scan_reverse(uint32_t const value)
__forceinline uint64_t __cdecl right_shift_with_rounding(bool const is_negative, uint64_t const value, uint32_t const shift, bool const has_zero_tail)
SLD_STATUS __cdecl assemble_floating_point_value_t(bool const is_negative, int32_t const exponent, uint64_t const mantissa, FloatingType &result)

Referenced by assemble_floating_point_value_from_big_integer(), convert_decimal_string_to_floating_type_common(), and convert_hexadecimal_string_to_floating_type_common().

◆ assemble_floating_point_value_from_big_integer()

SLD_STATUS __cdecl __crt_strtox::assemble_floating_point_value_from_big_integer ( big_integer const integer_value,
uint32_t const  integer_bits_of_precision,
bool const  is_negative,
bool const  has_nonzero_fractional_part,
floating_point_value const result 
)
throw (
)
inline

Definition at line 871 of file corecrt_internal_strtox.h.

878{
879 int32_t const base_exponent = result.mantissa_bits() - 1;
880
881 // Very fast case: If we have fewer than 64 bits of precision, we can just
882 // take the two low order elements from the big_integer:
883 if (integer_bits_of_precision <= 64)
884 {
885 int32_t const exponent = base_exponent;
886
887 uint32_t const mantissa_low = integer_value._used > 0 ? integer_value._data[0] : 0;
888 uint32_t const mantissa_high = integer_value._used > 1 ? integer_value._data[1] : 0;
889 uint64_t const mantissa =
890 mantissa_low +
891 (static_cast<uint64_t>(mantissa_high) << 32);
892
893 return assemble_floating_point_value(mantissa, exponent, is_negative, !has_nonzero_fractional_part, result);
894 }
895
896 uint32_t const top_element_bits = integer_bits_of_precision % 32;
897 uint32_t const top_element_index = integer_bits_of_precision / 32;
898
899 uint32_t const middle_element_index = top_element_index - 1;
900 uint32_t const bottom_element_index = top_element_index - 2;
901
902 // Pretty fast case: If the top 64 bits occupy only two elements, we can
903 // just combine those two elements:
904 if (top_element_bits == 0)
905 {
906 int32_t const exponent = base_exponent + bottom_element_index * 32;
907
908 uint64_t const mantissa =
909 integer_value._data[bottom_element_index] +
910 (static_cast<uint64_t>(integer_value._data[middle_element_index]) << 32);
911
912 bool has_zero_tail = !has_nonzero_fractional_part;
913 for (uint32_t i = 0; i != bottom_element_index; ++i)
914 {
915 has_zero_tail &= integer_value._data[i] == 0;
916 }
917
918 return assemble_floating_point_value(mantissa, exponent, is_negative, has_zero_tail, result);
919 }
920
921 // Not quite so fast case: The top 64 bits span three elements in the big
922 // integer. Assemble the three pieces:
923 uint32_t const top_element_mask = (1u << top_element_bits) - 1;
924 uint32_t const top_element_shift = 64 - top_element_bits; // Left
925
926 uint32_t const middle_element_shift = top_element_shift - 32; // Left
927
928 uint32_t const bottom_element_bits = 32 - top_element_bits;
929 uint32_t const bottom_element_mask = ~top_element_mask;
930 uint32_t const bottom_element_shift = 32 - bottom_element_bits; // Right
931
932 int32_t const exponent = base_exponent + bottom_element_index * 32 + top_element_bits;
933
934 uint64_t const mantissa =
935 (static_cast<uint64_t>(integer_value._data[top_element_index] & top_element_mask) << top_element_shift) +
936 (static_cast<uint64_t>(integer_value._data[middle_element_index]) << middle_element_shift) +
937 (static_cast<uint64_t>(integer_value._data[bottom_element_index] & bottom_element_mask) >> bottom_element_shift);
938
939 bool has_zero_tail =
940 !has_nonzero_fractional_part &&
941 (integer_value._data[bottom_element_index] & top_element_mask) == 0;
942
943 for (uint32_t i = 0; i != bottom_element_index; ++i)
944 {
945 has_zero_tail &= integer_value._data[i] == 0;
946 }
947
948 return assemble_floating_point_value(mantissa, exponent, is_negative, has_zero_tail, result);
949}
SLD_STATUS __cdecl assemble_floating_point_value(uint64_t const initial_mantissa, int32_t const initial_exponent, bool const is_negative, bool const has_zero_tail, floating_point_value const &result)

Referenced by convert_decimal_string_to_floating_type_common().

◆ assemble_floating_point_value_t()

template<typename FloatingType >
SLD_STATUS __cdecl __crt_strtox::assemble_floating_point_value_t ( bool const  is_negative,
int32_t const  exponent,
uint64_t const  mantissa,
FloatingType &  result 
)
throw (
)

Definition at line 718 of file corecrt_internal_strtox.h.

724{
725 using floating_traits = __acrt_floating_type_traits<FloatingType>;
726 using components_type = typename floating_traits::components_type;
727
728 components_type& result_components = reinterpret_cast<components_type&>(result);
729 result_components._sign = is_negative;
730 result_components._exponent = exponent + floating_traits::exponent_bias;
731 result_components._mantissa = mantissa;
732 return SLD_OK;
733}

Referenced by assemble_floating_point_value().

◆ assemble_floating_point_zero() [1/3]

void __cdecl __crt_strtox::assemble_floating_point_zero ( bool const  is_negative,
_LDBL12 result 
)
throw (
)

Definition at line 540 of file atoldbl.cpp.

541{
542 uint16_t const sign_bit{static_cast<uint16_t>(is_negative ? MSB_USHORT : 0x0000)};
543
544 // Zero is all zero bits with an optional sign bit:
545 *U_XT_12 (&result) = 0;
546 *UL_MANLO_12(&result) = 0;
547 *UL_MANHI_12(&result) = 0;
548 *U_EXP_12 (&result) = sign_bit;
549}

Referenced by assemble_floating_point_value(), assemble_floating_point_zero(), convert_decimal_string_to_floating_type_common(), and parse_floating_point_write_result().

◆ assemble_floating_point_zero() [2/3]

void __cdecl __crt_strtox::assemble_floating_point_zero ( bool const  is_negative,
floating_point_value const result 
)
throw (
)
inline

Definition at line 515 of file corecrt_internal_strtox.h.

516{
517 if (result.is_double())
518 {
519 assemble_floating_point_zero(is_negative, result.as_double());
520 }
521 else
522 {
523 assemble_floating_point_zero(is_negative, result.as_float());
524 }
525}
void __cdecl assemble_floating_point_zero(bool const is_negative, _LDBL12 &result)
Definition: atoldbl.cpp:540

◆ assemble_floating_point_zero() [3/3]

template<typename FloatingType >
void __cdecl __crt_strtox::assemble_floating_point_zero ( bool const  is_negative,
FloatingType &  result 
)
throw (
)

Definition at line 504 of file corecrt_internal_strtox.h.

505{
506 using floating_traits = __acrt_floating_type_traits<FloatingType>;
507 using components_type = typename floating_traits::components_type;
508
509 components_type& result_components = reinterpret_cast<components_type&>(result);
510 result_components._sign = is_negative ? 1 : 0;
511 result_components._exponent = 0;
512 result_components._mantissa = 0;
513}

◆ bit_scan_reverse() [1/3]

__forceinline uint32_t __cdecl __crt_strtox::bit_scan_reverse ( big_integer const x)
throw (
)

Definition at line 182 of file corecrt_internal_big_integer.h.

183{
184 if (x._used == 0)
185 {
186 return 0;
187 }
188
189 return (x._used - 1) * big_integer::element_bits + bit_scan_reverse(x._data[x._used - 1]);
190}

◆ bit_scan_reverse() [2/3]

__forceinline uint32_t __cdecl __crt_strtox::bit_scan_reverse ( uint32_t const  value)
throw (
)

Definition at line 162 of file corecrt_internal_big_integer.h.

163{
164 unsigned long index = 0;
166 return index + 1;
167 return 0;
168}
GLuint index
Definition: glext.h:6031
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask)
Definition: intrin_arm.h:180

Referenced by assemble_floating_point_value(), bit_scan_reverse(), convert_decimal_string_to_floating_type_common(), and shift_left().

◆ bit_scan_reverse() [3/3]

__forceinline uint32_t __cdecl __crt_strtox::bit_scan_reverse ( uint64_t const  value)
throw (
)

Definition at line 170 of file corecrt_internal_big_integer.h.

171{
172 if (value > UINT32_MAX)
173 {
174 return bit_scan_reverse(reinterpret_cast<uint32_t const*>(&value)[1]) + 32;
175 }
176 else
177 {
178 return bit_scan_reverse(reinterpret_cast<uint32_t const*>(&value)[0]);
179 }
180}
#define UINT32_MAX
Definition: intsafe.h:153

◆ common_convert_to_ldbl12()

static SLD_STATUS __cdecl __crt_strtox::common_convert_to_ldbl12 ( floating_point_string const immutable_data,
bool const  is_hexadecimal,
_LDBL12 result 
)
throw (
)
static

Definition at line 592 of file atoldbl.cpp.

597{
598 floating_point_string data = immutable_data;
599
600 // Cap the number of digits to LD_MAX_MAN_LEN, and round the last digit:
601 if (data._mantissa_count > LD_MAX_MAN_LEN)
602 {
603 if (data._mantissa[LD_MAX_MAN_LEN] >= (is_hexadecimal ? 8 : 5))
604 {
606 }
607
608 data._mantissa_count = LD_MAX_MAN_LEN;
609 }
610
611 // The input exponent is an adjustment from the left (so 12.3456 is represented
612 // as a mantiss a of 123456 with an exponent of 2), but the legacy functions
613 // used here expect an adjustment from the right (so 12.3456 is represented
614 // with an exponent of -4).
615 int const exponent_adjustment_multiplier = is_hexadecimal ? 4 : 1;
616 data._exponent -= data._mantissa_count * exponent_adjustment_multiplier;
617
618 if (is_hexadecimal)
619 {
620 convert_mantissa_to_ld12<16>(data._mantissa, data._mantissa_count, &result);
621 multiply_two_pow_ld12(&result, data._exponent);
622 }
623 else
624 {
625 convert_mantissa_to_ld12<10>(data._mantissa, data._mantissa_count, &result);
626 multiply_ten_pow_ld12(&result, data._exponent);
627 }
628
629 if (data._is_negative)
630 {
631 *U_EXP_12(&result) |= 0x8000;
632 }
633
634 // If the combination of the mantissa and the exponent produced an infinity,
635 // we've overflowed the range of the _LDBL12.
636 if ((*U_EXP_12(&result) & LD_MAXEXP) == LD_MAXEXP)
637 {
638 return SLD_OVERFLOW;
639 }
640
641 return SLD_OK;
642}
static __forceinline void __cdecl multiply_two_pow_ld12(_LDBL12 *const ld12, int const power)
Definition: atoldbl.cpp:460
static __forceinline void __cdecl multiply_ten_pow_ld12(_LDBL12 *const pld12, int pow)
Definition: atoldbl.cpp:417
#define LD_MAX_MAN_LEN
Definition: atoldbl.cpp:29
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by convert_decimal_string_to_floating_type(), and convert_hexadecimal_string_to_floating_type().

◆ convert_decimal_string_to_floating_type() [1/2]

SLD_STATUS __cdecl __crt_strtox::convert_decimal_string_to_floating_type ( floating_point_string const data,
_LDBL12 result 
)
throw (
)

Definition at line 644 of file atoldbl.cpp.

648{
649 return common_convert_to_ldbl12(data, false, result);
650}
static SLD_STATUS __cdecl common_convert_to_ldbl12(floating_point_string const &immutable_data, bool const is_hexadecimal, _LDBL12 &result)
Definition: atoldbl.cpp:592

Referenced by parse_floating_point_write_result().

◆ convert_decimal_string_to_floating_type() [2/2]

template<typename FloatingType >
SLD_STATUS __cdecl __crt_strtox::convert_decimal_string_to_floating_type ( floating_point_string const data,
FloatingType &  result 
)
throw (
)

Definition at line 1176 of file corecrt_internal_strtox.h.

1180{
1182}
SLD_STATUS __cdecl convert_decimal_string_to_floating_type_common(floating_point_string const &data, floating_point_value const &result)

◆ convert_decimal_string_to_floating_type_common()

SLD_STATUS __cdecl __crt_strtox::convert_decimal_string_to_floating_type_common ( floating_point_string const data,
floating_point_value const result 
)
throw (
)
inline

Definition at line 992 of file corecrt_internal_strtox.h.

996{
997 // To generate an N bit mantissa we require N + 1 bits of precision. The
998 // extra bit is used to correctly round the mantissa (if there are fewer bits
999 // than this available, then that's totally okay; in that case we use what we
1000 // have and we don't need to round).
1001 uint32_t const required_bits_of_precision = result.mantissa_bits() + 1;
1002
1003 // The input is of the form 0.mantissa x 10^exponent, where 'mantissa' are
1004 // the decimal digits of the mantissa and 'exponent' is the decimal exponent.
1005 // We decompose the mantissa into two parts: an integer part and a fractional
1006 // part. If the exponent is positive, then the integer part consists of the
1007 // first 'exponent' digits, or all present digits if there are fewer digits.
1008 // If the exponent is zero or negative, then the integer part is empty. In
1009 // either case, the remaining digits form the fractional part of the mantissa.
1010 uint32_t const positive_exponent = static_cast<uint32_t>(__max(0, data._exponent));
1011 uint32_t const integer_digits_present = __min(positive_exponent, data._mantissa_count);
1012 uint32_t const integer_digits_missing = positive_exponent - integer_digits_present;
1013 uint8_t const* const integer_first = data._mantissa;
1014 uint8_t const* const integer_last = data._mantissa + integer_digits_present;
1015
1016 uint8_t const* const fractional_first = integer_last;
1017 uint8_t const* const fractional_last = data._mantissa + data._mantissa_count;
1018 uint32_t const fractional_digits_present = static_cast<uint32_t>(fractional_last - fractional_first);
1019
1020 // First, we accumulate the integer part of the mantissa into a big_integer:
1021 big_integer integer_value{};
1022 accumulate_decimal_digits_into_big_integer(integer_first, integer_last, integer_value);
1023
1024 if (integer_digits_missing > 0)
1025 {
1026 if (!multiply_by_power_of_ten(integer_value, integer_digits_missing))
1027 {
1028 assemble_floating_point_infinity(data._is_negative, result);
1029 return SLD_OVERFLOW;
1030 }
1031 }
1032
1033 // At this point, the integer_value contains the value of the integer part
1034 // of the mantissa. If either [1] this number has more than the required
1035 // number of bits of precision or [2] the mantissa has no fractional part,
1036 // then we can assemble the result immediately:
1037 uint32_t const integer_bits_of_precision = bit_scan_reverse(integer_value);
1038 if (integer_bits_of_precision >= required_bits_of_precision ||
1039 fractional_digits_present == 0)
1040 {
1042 integer_value,
1043 integer_bits_of_precision,
1044 data._is_negative,
1045 fractional_digits_present != 0,
1046 result);
1047 }
1048
1049 // Otherwise, we did not get enough bits of precision from the integer part,
1050 // and the mantissa has a fractional part. We parse the fractional part of
1051 // the mantsisa to obtain more bits of precision. To do this, we convert
1052 // the fractional part into an actual fraction N/M, where the numerator N is
1053 // computed from the digits of the fractional part, and the denominator M is
1054 // computed as the power of 10 such that N/M is equal to the value of the
1055 // fractional part of the mantissa.
1056 big_integer fractional_numerator{};
1057 accumulate_decimal_digits_into_big_integer(fractional_first, fractional_last, fractional_numerator);
1058
1059 uint32_t const fractional_denominator_exponent = data._exponent < 0
1060 ? fractional_digits_present + static_cast<uint32_t>(-data._exponent)
1061 : fractional_digits_present;
1062
1063 big_integer fractional_denominator = make_big_integer(1);
1064 if (!multiply_by_power_of_ten(fractional_denominator, fractional_denominator_exponent))
1065 {
1066 // If there were any digits in the integer part, it is impossible to
1067 // underflow (because the exponent cannot possibly be small enough),
1068 // so if we underflow here it is a true underflow and we return zero.
1070 return SLD_UNDERFLOW;
1071 }
1072
1073 // Because we are using only the fractional part of the mantissa here, the
1074 // numerator is guaranteed to be smaller than the denominator. We normalize
1075 // the fraction such that the most significant bit of the numerator is in
1076 // the same position as the most significant bit in the denominator. This
1077 // ensures that when we later shift the numerator N bits to the left, we
1078 // will produce N bits of precision.
1079 uint32_t const fractional_numerator_bits = bit_scan_reverse(fractional_numerator);
1080 uint32_t const fractional_denominator_bits = bit_scan_reverse(fractional_denominator);
1081
1082 uint32_t const fractional_shift = fractional_denominator_bits > fractional_numerator_bits
1083 ? fractional_denominator_bits - fractional_numerator_bits
1084 : 0;
1085
1086 if (fractional_shift > 0)
1087 {
1088 shift_left(fractional_numerator, fractional_shift);
1089 }
1090
1091 uint32_t const required_fractional_bits_of_precision =
1092 required_bits_of_precision -
1093 integer_bits_of_precision;
1094
1095 uint32_t remaining_bits_of_precision_required = required_fractional_bits_of_precision;
1096 if (integer_bits_of_precision > 0)
1097 {
1098 // If the fractional part of the mantissa provides no bits of precision
1099 // and cannot affect rounding, we can just take whatever bits we got from
1100 // the integer part of the mantissa. This is the case for numbers like
1101 // 5.0000000000000000000001, where the significant digits of the fractional
1102 // part start so far to the right that they do not affect the floating
1103 // point representation.
1104 //
1105 // If the fractional shift is exactly equal to the number of bits of
1106 // precision that we require, then no fractional bits will be part of the
1107 // result, but the result may affect rounding. This is e.g. the case for
1108 // large, odd integers with a fractional part greater than or equal to .5.
1109 // Thus, we need to do the division to correctl round the result.
1110 if (fractional_shift > remaining_bits_of_precision_required)
1111 {
1113 integer_value,
1114 integer_bits_of_precision,
1115 data._is_negative,
1116 fractional_digits_present != 0,
1117 result);
1118 }
1119
1120 remaining_bits_of_precision_required -= fractional_shift;
1121 }
1122
1123 // If there was no integer part of the mantissa, we will need to compute the
1124 // exponent from the fractional part. The fractional exponent is the power
1125 // of two by which we must multiply the fractional part to move it into the
1126 // range [1.0, 2.0). This will either be the same as the shift we computed
1127 // earlier, or one greater than that shift:
1128 uint32_t const fractional_exponent = fractional_numerator < fractional_denominator
1129 ? fractional_shift + 1
1130 : fractional_shift;
1131
1132 shift_left(fractional_numerator, remaining_bits_of_precision_required);
1133 uint64_t fractional_mantissa = divide(fractional_numerator, fractional_denominator);
1134
1135 bool has_zero_tail = fractional_numerator._used == 0;
1136
1137 // We may have produced more bits of precision than were required. Check,
1138 // and remove any "extra" bits:
1139 uint32_t const fractional_mantissa_bits = bit_scan_reverse(fractional_mantissa);
1140 if (fractional_mantissa_bits > required_fractional_bits_of_precision)
1141 {
1142 uint32_t const shift = fractional_mantissa_bits - required_fractional_bits_of_precision;
1143 has_zero_tail = has_zero_tail && (fractional_mantissa & ((1ull << shift) - 1)) == 0;
1144 fractional_mantissa >>= shift;
1145 }
1146
1147 // Compose the mantissa from the integer and fractional parts:
1148 uint32_t const integer_mantissa_low = integer_value._used > 0 ? integer_value._data[0] : 0;
1149 uint32_t const integer_mantissa_high = integer_value._used > 1 ? integer_value._data[1] : 0;
1150 uint64_t const integer_mantissa =
1151 integer_mantissa_low +
1152 (static_cast<uint64_t>(integer_mantissa_high) << 32);
1153
1154 uint64_t const complete_mantissa =
1155 (integer_mantissa << required_fractional_bits_of_precision) +
1156 fractional_mantissa;
1157
1158 // Compute the final exponent:
1159 // * If the mantissa had an integer part, then the exponent is one less than
1160 // the number of bits we obtained from the integer part. (It's one less
1161 // because we are converting to the form 1.11111, with one 1 to the left
1162 // of the decimal point.)
1163 // * If the mantissa had no integer part, then the exponent is the fractional
1164 // exponent that we computed.
1165 // Then, in both cases, we subtract an additional one from the exponent, to
1166 // account for the fact that we've generated an extra bit of precision, for
1167 // use in rounding.
1168 int32_t const final_exponent = integer_bits_of_precision > 0
1169 ? integer_bits_of_precision - 2
1170 : -static_cast<int32_t>(fractional_exponent) - 1;
1171
1172 return assemble_floating_point_value(complete_mantissa, final_exponent, data._is_negative, has_zero_tail, result);
1173}
#define __min(a, b)
Definition: stdlib.h:102
#define __max(a, b)
Definition: stdlib.h:101
#define shift
Definition: input.c:1755
__forceinline big_integer __cdecl make_big_integer(uint64_t const value)
uint64_t __cdecl divide(big_integer &numerator, big_integer const &denominator)
__forceinline bool __cdecl shift_left(big_integer &x, uint32_t const n)
__forceinline void __cdecl accumulate_decimal_digits_into_big_integer(uint8_t const *const first_digit, uint8_t const *const last_digit, big_integer &result)
SLD_STATUS __cdecl assemble_floating_point_value_from_big_integer(big_integer const &integer_value, uint32_t const integer_bits_of_precision, bool const is_negative, bool const has_nonzero_fractional_part, floating_point_value const &result)

Referenced by convert_decimal_string_to_floating_type().

◆ convert_hexadecimal_string_to_floating_type() [1/2]

SLD_STATUS __cdecl __crt_strtox::convert_hexadecimal_string_to_floating_type ( floating_point_string const data,
_LDBL12 result 
)
throw (
)

Definition at line 652 of file atoldbl.cpp.

656{
657 return common_convert_to_ldbl12(data, true, result);
658}

Referenced by parse_floating_point_write_result().

◆ convert_hexadecimal_string_to_floating_type() [2/2]

template<typename FloatingType >
SLD_STATUS __cdecl __crt_strtox::convert_hexadecimal_string_to_floating_type ( floating_point_string const data,
FloatingType &  result 
)
throw (
)

Definition at line 1212 of file corecrt_internal_strtox.h.

1216{
1218}
SLD_STATUS __cdecl convert_hexadecimal_string_to_floating_type_common(floating_point_string const &data, floating_point_value const &result)

◆ convert_hexadecimal_string_to_floating_type_common()

SLD_STATUS __cdecl __crt_strtox::convert_hexadecimal_string_to_floating_type_common ( floating_point_string const data,
floating_point_value const result 
)
throw (
)
inline

Definition at line 1184 of file corecrt_internal_strtox.h.

1188{
1189 uint64_t mantissa = 0;
1190 int32_t exponent = data._exponent + result.mantissa_bits() - 1;
1191
1192 // Accumulate bits into the mantissa buffer
1193 uint8_t const* const mantissa_last = data._mantissa + data._mantissa_count;
1194 uint8_t const* mantissa_it = data._mantissa;
1195 while (mantissa_it != mantissa_last && mantissa <= result.normal_mantissa_mask())
1196 {
1197 mantissa *= 16;
1198 mantissa += *mantissa_it++;
1199 exponent -= 4; // The exponent is in binary; log2(16) == 4
1200 }
1201
1202 bool has_zero_tail = true;
1203 while (mantissa_it != mantissa_last && has_zero_tail)
1204 {
1205 has_zero_tail = has_zero_tail && *mantissa_it++ == 0;
1206 }
1207
1208 return assemble_floating_point_value(mantissa, exponent, data._is_negative, has_zero_tail, result);
1209}

Referenced by convert_hexadecimal_string_to_floating_type().

◆ count_sequential_high_zeroes()

__forceinline uint32_t __cdecl __crt_strtox::count_sequential_high_zeroes ( uint32_t const  u)
throw (
)

Definition at line 670 of file corecrt_internal_big_integer.h.

671{
672 unsigned long result;
673 return _BitScanReverse(&result, u) ? 31 - result : 32;
674}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240

Referenced by divide().

◆ divide()

uint64_t __cdecl __crt_strtox::divide ( big_integer numerator,
big_integer const denominator 
)
throw (
)
inline

Definition at line 733 of file corecrt_internal_big_integer.h.

737{
738 // If the numerator is zero, then both the quotient and remainder are zero:
739 if (numerator._used == 0)
740 {
741 return 0;
742 }
743
744 // If the denominator is zero, then uh oh. We can't divide by zero:
745 if (denominator._used == 0)
746 {
747 _ASSERTE(("Division by zero", false));
748 return 0;
749 }
750
751 uint32_t max_numerator_element_index = numerator._used - 1;
752 uint32_t max_denominator_element_index = denominator._used - 1;
753
754 // The numerator and denominator are both nonzero. If the denominator is
755 // only one element wide, we can take the fast route:
756 if (max_denominator_element_index == 0)
757 {
758 uint32_t const small_denominator = denominator._data[0];
759
760 if (small_denominator == 1)
761 {
762 uint32_t const quotient = numerator._data[0];
763 numerator = big_integer{};
764 return quotient;
765 }
766
767 if (max_numerator_element_index == 0)
768 {
769 uint32_t const small_numerator = numerator._data[0];
770
771 numerator = big_integer{};
772 numerator._data[0] = small_numerator % small_denominator;
773 numerator._used = numerator._data[0] > 0 ? 1 : 0;
774 return small_numerator / small_denominator;
775 }
776
777 // We count down in the next loop, so the last assignment to quotient
778 // will be the correct one.
779 uint64_t quotient = 0;
780
781 uint64_t uu = 0;
782 for (uint32_t iv = max_numerator_element_index; iv != static_cast<uint32_t>(-1); --iv)
783 {
784 uu = (uu << 32) | numerator._data[iv];
785 quotient = (quotient << 32) + static_cast<uint32_t>(uu / small_denominator);
786 uu %= small_denominator;
787 }
788
789 numerator = big_integer{};
790 numerator._data[1] = static_cast<uint32_t>(uu >> 32);
791 numerator._data[0] = static_cast<uint32_t>(uu );
792 numerator._used = numerator._data[1] > 0 ? 2 : 1;
793 return quotient;
794 }
795
796 if (max_denominator_element_index > max_numerator_element_index)
797 {
798 return 0;
799 }
800
801 uint32_t cu_den = max_denominator_element_index + 1;
802 int32_t cu_diff = max_numerator_element_index - max_denominator_element_index;
803
804 // Determine whether the result will have cu_diff or cu_diff + 1 digits:
805 int32_t cu_quo = cu_diff;
806 for (int32_t iu = max_numerator_element_index; ; --iu)
807 {
808 if (iu < cu_diff)
809 {
810 ++cu_quo;
811 break;
812 }
813
814 if (denominator._data[iu - cu_diff] != numerator._data[iu])
815 {
816 if (denominator._data[iu - cu_diff] < numerator._data[iu])
817 {
818 ++cu_quo;
819 }
820
821 break;
822 }
823 }
824
825 if (cu_quo == 0)
826 {
827 return 0;
828 }
829
830 // Get the uint to use for the trial divisions. We normalize so the
831 // high bit is set:
832 uint32_t u_den = denominator._data[cu_den - 1];
833 uint32_t u_den_next = denominator._data[cu_den - 2];
834
835 uint32_t cbit_shift_left = count_sequential_high_zeroes(u_den);
836 uint32_t cbit_shift_right = 32 - cbit_shift_left;
837 if (cbit_shift_left > 0)
838 {
839 u_den = (u_den << cbit_shift_left) | (u_den_next >> cbit_shift_right);
840 u_den_next <<= cbit_shift_left;
841
842 if (cu_den > 2)
843 {
844 u_den_next |= denominator._data[cu_den - 3] >> cbit_shift_right;
845 }
846 }
847
848 uint64_t quotient{};
849 for (int32_t iu = cu_quo; --iu >= 0; )
850 {
851 // Get the high (normalized) bits of the numerator:
852 uint32_t u_num_hi = (iu + cu_den <= max_numerator_element_index)
853 ? numerator._data[iu + cu_den]
854 : 0;
855
856 uint64_t uu_num = numerator._data[iu + cu_den - 1];
857 reinterpret_cast<uint32_t*>(&uu_num)[1] = u_num_hi;
858
859 uint32_t u_num_next = numerator._data[iu + cu_den - 2];
860 if (cbit_shift_left > 0)
861 {
862 uu_num = (uu_num << cbit_shift_left) | (u_num_next >> cbit_shift_right);
863 u_num_next <<= cbit_shift_left;
864
865 if (iu + cu_den >= 3)
866 {
867 u_num_next |= numerator._data[iu + cu_den - 3] >> cbit_shift_right;
868 }
869 }
870
871 // Divide to get the quotient digit:
872 uint64_t uu_quo = uu_num / u_den;
873 uint64_t uu_rem = static_cast<uint32_t>(uu_num % u_den);
874
875 if (uu_quo > UINT32_MAX)
876 {
877 uu_rem += u_den * (uu_quo - UINT32_MAX);
878 uu_quo = UINT32_MAX;
879 }
880
881 while (uu_rem <= UINT32_MAX && uu_quo * u_den_next > ((uu_rem << 32) | u_num_next))
882 {
883 --uu_quo;
884 uu_rem += u_den;
885 }
886
887 // Multiply and subtract. Note that uu_quo may be one too large. If
888 // we have a borrow at the end, we'll add the denominator back on and
889 // decrement uu_quo.
890 if (uu_quo > 0)
891 {
892 uint64_t uu_borrow = 0;
893
894 for (uint32_t iu2 = 0; iu2 < cu_den; ++iu2)
895 {
896 uu_borrow += multiply_64_32(uu_quo, denominator._data[iu2]);
897
898 uint32_t const u_sub = static_cast<uint32_t>(uu_borrow);
899 uu_borrow >>= 32;
900 if (numerator._data[iu + iu2] < u_sub)
901 {
902 ++uu_borrow;
903 }
904
905 numerator._data[iu + iu2] -= u_sub;
906 }
907
908 if (u_num_hi < uu_borrow)
909 {
910 // Add, tracking carry:
911 uint32_t u_carry = 0;
912 for (uint32_t iu2 = 0; iu2 < cu_den; ++iu2)
913 {
914 uint64_t const sum =
915 static_cast<uint64_t>(numerator._data[iu + iu2]) +
916 static_cast<uint64_t>(denominator._data[iu2]) +
917 u_carry;
918
919 numerator._data[iu + iu2] = static_cast<uint32_t>(sum);
920 u_carry = sum >> 32;
921 }
922
923 --uu_quo;
924 }
925
926 max_numerator_element_index = iu + cu_den - 1;
927 }
928
929 quotient = (quotient << 32) + static_cast<uint32_t>(uu_quo);
930 }
931
932 // Trim the remainder:
933 for (uint32_t i = max_numerator_element_index + 1; i < numerator._used; ++i)
934 {
935 numerator._data[i] = 0;
936 }
937
938 numerator._used = max_numerator_element_index + 1;
939 while (numerator._used != 0 && numerator._data[numerator._used - 1] == 0)
940 {
941 --numerator._used;
942 }
943
944 return quotient;
945}
#define _ASSERTE(expr)
Definition: crtdbg.h:114
__forceinline uint64_t __cdecl multiply_64_32(uint64_t const multiplicand, uint32_t const multiplier)
__forceinline uint32_t __cdecl count_sequential_high_zeroes(uint32_t const u)
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35

Referenced by convert_decimal_string_to_floating_type_common(), and convert_to_fos_high_precision().

◆ is_digit_or_nondigit()

__forceinline bool __cdecl __crt_strtox::is_digit_or_nondigit ( int const  c)
throw (
)

Definition at line 163 of file corecrt_internal_strtox.h.

164{
165 if (c >= '0' && c <= '9')
166 return true;
167
168 if (c >= 'a' && c <= 'z')
169 return true;
170
171 if (c >= 'A' && c <= 'Z')
172 return true;
173
174 if (c == '_')
175 return true;
176
177 return false;
178}
const GLubyte * c
Definition: glext.h:8905

Referenced by parse_floating_point_possible_nan().

◆ is_overflow_condition()

template<typename UnsignedInteger >
bool __crt_strtox::is_overflow_condition ( unsigned const  flags,
UnsignedInteger const  number 
)
throw (
)

Definition at line 205 of file corecrt_internal_strtox.h.

206{
207 if (flags & FL_OVERFLOW)
208 return true;
209
210 if (flags & FL_SIGNED)
211 {
212 if ((flags & FL_NEGATIVE) != 0 && number > static_cast<UnsignedInteger>(-minimum_signed_value(UnsignedInteger())))
213 return true;
214
215 if ((flags & FL_NEGATIVE) == 0 && number > static_cast<UnsignedInteger>(maximum_signed_value(UnsignedInteger())))
216 return true;
217 }
218
219 return false;
220}
GLbitfield flags
Definition: glext.h:7161
static unsigned int number
Definition: dsound.c:1479
long minimum_signed_value(unsigned long)
long maximum_signed_value(unsigned long)

Referenced by parse_integer().

◆ is_space() [1/2]

__forceinline bool __cdecl __crt_strtox::is_space ( char const  c,
_locale_t const  locale 
)
throw (
)

Definition at line 180 of file corecrt_internal_strtox.h.

181{
182 return _isspace_l(static_cast<int>(static_cast<unsigned char>(c)), locale) != 0;
183}
Definition: _locale.h:75
#define _isspace_l(_Char, _Locale)
Definition: ctype.h:648

Referenced by __crt_stdio_input::skip_whitespace().

◆ is_space() [2/2]

__forceinline bool __cdecl __crt_strtox::is_space ( wchar_t const  c,
_locale_t   
)
throw (
)

Definition at line 185 of file corecrt_internal_strtox.h.

186{
187 return iswspace(c) != 0;
188}
#define iswspace(_c)
Definition: ctype.h:669

◆ is_zero()

__forceinline bool __cdecl __crt_strtox::is_zero ( big_integer const value)
throw (
)

Definition at line 157 of file corecrt_internal_big_integer.h.

158{
159 return value._used == 0;
160}

Referenced by convert_to_fos_high_precision().

◆ make_big_integer()

__forceinline big_integer __cdecl __crt_strtox::make_big_integer ( uint64_t const  value)
throw (
)

Definition at line 132 of file corecrt_internal_big_integer.h.

133{
134 big_integer x{};
135 x._data[0] = value & 0xffffffff;
136 x._data[1] = value >> 32;
137 x._used = x._data[1] == 0 ? 1 : 2;
138 return x;
139}

Referenced by convert_decimal_string_to_floating_type_common(), and convert_to_fos_high_precision().

◆ make_big_integer_power_of_two()

__forceinline big_integer __cdecl __crt_strtox::make_big_integer_power_of_two ( uint32_t const  power)
throw (
)

Definition at line 141 of file corecrt_internal_big_integer.h.

142{
143 uint32_t const one = 1;
144
145 big_integer x{};
146
147 uint32_t const element_index = power / big_integer::element_bits;
148 uint32_t const bit_index = power % big_integer::element_bits;
149
150 memset(x._data, 0, element_index * sizeof(uint32_t));
151 x._data[element_index] = (one << bit_index);
152 x._used = element_index + 1;
153
154 return x;
155}
float power
Definition: d3drm.c:3372
#define memset(x, y, z)
Definition: compat.h:39
int one
Definition: sehframes.cpp:28

Referenced by convert_to_fos_high_precision().

◆ make_c_string_character_source()

template<typename Character , typename EndPointer >
c_string_character_source< Character > __cdecl __crt_strtox::make_c_string_character_source ( Character const *const  string,
EndPointer const  end 
)
throw (
)

◆ make_input_adapter_character_source()

template<typename InputAdapter >
input_adapter_character_source< InputAdapter > __cdecl __crt_strtox::make_input_adapter_character_source ( InputAdapter *const  input_adapter,
uint64_t const  width,
bool *const  succeeded 
)
throw (
)

◆ maximum_signed_value() [1/2]

__int64 __crt_strtox::maximum_signed_value ( unsigned  __int64)
throw (
)
inline

Definition at line 194 of file corecrt_internal_strtox.h.

194{ return _I64_MAX; }
#define _I64_MAX
Definition: limits.h:62

◆ maximum_signed_value() [2/2]

long __crt_strtox::maximum_signed_value ( unsigned long  )
throw (
)
inline

Definition at line 191 of file corecrt_internal_strtox.h.

191{ return LONG_MAX; }
#define LONG_MAX
Definition: intsafe.h:154

Referenced by is_overflow_condition(), and parse_integer().

◆ minimum_signed_value() [1/2]

__int64 __crt_strtox::minimum_signed_value ( unsigned  __int64)
throw (
)
inline

Definition at line 193 of file corecrt_internal_strtox.h.

193{ return _I64_MIN; }
#define _I64_MIN
Definition: limits.h:61

◆ minimum_signed_value() [2/2]

long __crt_strtox::minimum_signed_value ( unsigned long  )
throw (
)
inline

Definition at line 190 of file corecrt_internal_strtox.h.

190{ return LONG_MIN; }
#define LONG_MIN
Definition: intsafe.h:125

Referenced by is_overflow_condition(), and parse_integer().

◆ multiply() [1/2]

__forceinline bool __cdecl __crt_strtox::multiply ( big_integer multiplicand,
big_integer const multiplier 
)
throw (
)

Definition at line 373 of file corecrt_internal_big_integer.h.

374{
375 if (multiplier._used <= 1)
376 {
377 return multiply(multiplicand, multiplier._data[0]);
378 }
379
380 if (multiplicand._used <= 1)
381 {
382 uint32_t const small_multiplier = multiplicand._data[0];
383 multiplicand = multiplier;
384 return multiply(multiplicand, small_multiplier);
385 }
386
387 // We prefer more iterations on the inner loop and fewer on the outer:
388 bool const multiplier_is_shorter = multiplier._used < multiplicand._used;
389 uint32_t const* const rgu1 = multiplier_is_shorter ? multiplier._data : multiplicand._data;
390 uint32_t const* const rgu2 = multiplier_is_shorter ? multiplicand._data : multiplier._data;
391
392 uint32_t const cu1 = multiplier_is_shorter ? multiplier._used : multiplicand._used;
393 uint32_t const cu2 = multiplier_is_shorter ? multiplicand._used : multiplier._used;
394
395 big_integer result{};
396 for (uint32_t iu1 = 0; iu1 != cu1; ++iu1)
397 {
398 uint32_t const u_cur = rgu1[iu1];
399 if (u_cur == 0)
400 {
401 if (iu1 == result._used)
402 {
403 result._data[iu1] = 0;
404 result._used = iu1 + 1;
405 }
406
407 continue;
408 }
409
410 uint32_t u_carry = 0;
411 uint32_t iu_res = iu1;
412 for (uint32_t iu2 = 0; iu2 != cu2 && iu_res != big_integer::element_count; ++iu2, ++iu_res)
413 {
414 if (iu_res == result._used)
415 {
416 result._data[iu_res] = 0;
417 result._used = iu_res + 1;
418 }
419
420 u_carry = add_multiply_carry(result._data[iu_res], u_cur, rgu2[iu2], u_carry);
421 }
422
423 while (u_carry != 0 && iu_res != big_integer::element_count)
424 {
425 if (iu_res == result._used)
426 {
427 result._data[iu_res] = 0;
428 result._used = iu_res + 1;
429 }
430
431 u_carry = add_carry(result._data[iu_res++], 0, u_carry);
432 }
433
434 if (iu_res == big_integer::element_count)
435 {
436 multiplicand = big_integer{};
437 return false;
438 }
439 }
440
441 // Store the result in the multiplicand and compute the actual number of
442 // elements used:
443 multiplicand = result;
444 return true;
445}
__forceinline uint32_t __cdecl add_multiply_carry(uint32_t &u_add, uint32_t const u_mul_1, uint32_t const u_mul_2, uint32_t const u_carry)
__forceinline uint32_t __cdecl add_carry(uint32_t &u1, uint32_t const u2, uint32_t const u_carry)

◆ multiply() [2/2]

__forceinline bool __cdecl __crt_strtox::multiply ( big_integer multiplicand,
uint32_t const  multiplier 
)
throw (
)

Definition at line 332 of file corecrt_internal_big_integer.h.

333{
334 if (multiplier == 0)
335 {
336 multiplicand = big_integer{};
337 return true;
338 }
339
340 if (multiplier == 1)
341 {
342 return true;
343 }
344
345 if (multiplicand._used == 0)
346 {
347 return true;
348 }
349
350 uint32_t const carry = multiply_core(multiplicand._data, multiplicand._used, multiplier);
351 if (carry != 0)
352 {
353 if (multiplicand._used < big_integer::element_count)
354 {
355 multiplicand._data[multiplicand._used] = carry;
356 ++multiplicand._used;
357 }
358 else
359 {
360 multiplicand = big_integer{};
361 return false;
362 }
363 }
364
365 return true;
366}
__forceinline uint32_t __cdecl multiply_core(_Inout_updates_all_(multiplicand_count) uint32_t *const multiplicand, uint32_t const multiplicand_count, uint32_t const multiplier)

Referenced by accumulate_decimal_digits_into_big_integer(), convert_to_fos_high_precision(), multiply(), and multiply_by_power_of_ten().

◆ multiply_64_32()

__forceinline uint64_t __cdecl __crt_strtox::multiply_64_32 ( uint64_t const  multiplicand,
uint32_t const  multiplier 
)
throw (
)

Definition at line 719 of file corecrt_internal_big_integer.h.

723 {
724 return multiplicand * multiplier;
725 }

Referenced by divide().

◆ multiply_by_power_of_ten()

__forceinline bool __cdecl __crt_strtox::multiply_by_power_of_ten ( big_integer x,
uint32_t const  power 
)
throw (
)

Definition at line 450 of file corecrt_internal_big_integer.h.

451{
452 // To improve performance, we use a table of precomputed powers of ten, from
453 // 10^10 through 10^380, in increments of ten. In its unpacked form, as an
454 // array of big_integer objects, this table consists mostly of zero elements.
455 // Thus, we store the table in a packed form, trimming leading and trailing
456 // zero elements. We provide an index that is used to unpack powers from the
457 // table, using the function that appears after this function in this file.
458 //
459 // The minimum value representable with double precision is 5E-324. With
460 // this table we can thus compute most multiplications with a single multiply.
461 static uint32_t const large_power_data[] =
462 {
463 0x540be400, 0x00000002, 0x63100000, 0x6bc75e2d, 0x00000005, 0x40000000, 0x4674edea, 0x9f2c9cd0,
464 0x0000000c, 0xb9f56100, 0x5ca4bfab, 0x6329f1c3, 0x0000001d, 0xb5640000, 0xc40534fd, 0x926687d2,
465 0x6c3b15f9, 0x00000044, 0x10000000, 0x946590d9, 0xd762422c, 0x9a224501, 0x4f272617, 0x0000009f,
466 0x07950240, 0x245689c1, 0xc5faa71c, 0x73c86d67, 0xebad6ddc, 0x00000172, 0xcec10000, 0x63a22764,
467 0xefa418ca, 0xcdd17b25, 0x6bdfef70, 0x9dea3e1f, 0x0000035f, 0xe4000000, 0xcdc3fe6e, 0x66bc0c6a,
468 0x2e391f32, 0x5a450203, 0x71d2f825, 0xc3c24a56, 0x000007da, 0xa82e8f10, 0xaab24308, 0x8e211a7c,
469 0xf38ace40, 0x84c4ce0b, 0x7ceb0b27, 0xad2594c3, 0x00001249, 0xdd1a4000, 0xcc9f54da, 0xdc5961bf,
470 0xc75cabab, 0xf505440c, 0xd1bc1667, 0xfbb7af52, 0x608f8d29, 0x00002a94, 0x21000000, 0x17bb8a0c,
471 0x56af8ea4, 0x06479fa9, 0x5d4bb236, 0x80dc5fe0, 0xf0feaa0a, 0xa88ed940, 0x6b1a80d0, 0x00006323,
472 0x324c3864, 0x8357c796, 0xe44a42d5, 0xd9a92261, 0xbd3c103d, 0x91e5f372, 0xc0591574, 0xec1da60d,
473 0x102ad96c, 0x0000e6d3, 0x1e851000, 0x6e4f615b, 0x187b2a69, 0x0450e21c, 0x2fdd342b, 0x635027ee,
474 0xa6c97199, 0x8e4ae916, 0x17082e28, 0x1a496e6f, 0x0002196e, 0x32400000, 0x04ad4026, 0xf91e7250,
475 0x2994d1d5, 0x665bcdbb, 0xa23b2e96, 0x65fa7ddb, 0x77de53ac, 0xb020a29b, 0xc6bff953, 0x4b9425ab,
476 0x0004e34d, 0xfbc32d81, 0x5222d0f4, 0xb70f2850, 0x5713f2f3, 0xdc421413, 0xd6395d7d, 0xf8591999,
477 0x0092381c, 0x86b314d6, 0x7aa577b9, 0x12b7fe61, 0x000b616a, 0x1d11e400, 0x56c3678d, 0x3a941f20,
478 0x9b09368b, 0xbd706908, 0x207665be, 0x9b26c4eb, 0x1567e89d, 0x9d15096e, 0x7132f22b, 0xbe485113,
479 0x45e5a2ce, 0x001a7f52, 0xbb100000, 0x02f79478, 0x8c1b74c0, 0xb0f05d00, 0xa9dbc675, 0xe2d9b914,
480 0x650f72df, 0x77284b4c, 0x6df6e016, 0x514391c2, 0x2795c9cf, 0xd6e2ab55, 0x9ca8e627, 0x003db1a6,
481 0x40000000, 0xf4ecd04a, 0x7f2388f0, 0x580a6dc5, 0x43bf046f, 0xf82d5dc3, 0xee110848, 0xfaa0591c,
482 0xcdf4f028, 0x192ea53f, 0xbcd671a0, 0x7d694487, 0x10f96e01, 0x791a569d, 0x008fa475, 0xb9b2e100,
483 0x8288753c, 0xcd3f1693, 0x89b43a6b, 0x089e87de, 0x684d4546, 0xfddba60c, 0xdf249391, 0x3068ec13,
484 0x99b44427, 0xb68141ee, 0x5802cac3, 0xd96851f1, 0x7d7625a2, 0x014e718d, 0xfb640000, 0xf25a83e6,
485 0x9457ad0f, 0x0080b511, 0x2029b566, 0xd7c5d2cf, 0xa53f6d7d, 0xcdb74d1c, 0xda9d70de, 0xb716413d,
486 0x71d0ca4e, 0xd7e41398, 0x4f403a90, 0xf9ab3fe2, 0x264d776f, 0x030aafe6, 0x10000000, 0x09ab5531,
487 0xa60c58d2, 0x566126cb, 0x6a1c8387, 0x7587f4c1, 0x2c44e876, 0x41a047cf, 0xc908059e, 0xa0ba063e,
488 0xe7cfc8e8, 0xe1fac055, 0xef0144b2, 0x24207eb0, 0xd1722573, 0xe4b8f981, 0x071505ae, 0x7a3b6240,
489 0xcea45d4f, 0x4fe24133, 0x210f6d6d, 0xe55633f2, 0x25c11356, 0x28ebd797, 0xd396eb84, 0x1e493b77,
490 0x471f2dae, 0x96ad3820, 0x8afaced1, 0x4edecddb, 0x5568c086, 0xb2695da1, 0x24123c89, 0x107d4571,
491 0x1c410000, 0x6e174a27, 0xec62ae57, 0xef2289aa, 0xb6a2fbdd, 0x17e1efe4, 0x3366bdf2, 0x37b48880,
492 0xbfb82c3e, 0x19acde91, 0xd4f46408, 0x35ff6a4e, 0x67566a0e, 0x40dbb914, 0x782a3bca, 0x6b329b68,
493 0xf5afc5d9, 0x266469bc, 0xe4000000, 0xfb805ff4, 0xed55d1af, 0x9b4a20a8, 0xab9757f8, 0x01aefe0a,
494 0x4a2ca67b, 0x1ebf9569, 0xc7c41c29, 0xd8d5d2aa, 0xd136c776, 0x93da550c, 0x9ac79d90, 0x254bcba8,
495 0x0df07618, 0xf7a88809, 0x3a1f1074, 0xe54811fc, 0x59638ead, 0x97cbe710, 0x26d769e8, 0xb4e4723e,
496 0x5b90aa86, 0x9c333922, 0x4b7a0775, 0x2d47e991, 0x9a6ef977, 0x160b40e7, 0x0c92f8c4, 0xf25ff010,
497 0x25c36c11, 0xc9f98b42, 0x730b919d, 0x05ff7caf, 0xb0432d85, 0x2d2b7569, 0xa657842c, 0xd01fef10,
498 0xc77a4000, 0xe8b862e5, 0x10d8886a, 0xc8cd98e5, 0x108955c5, 0xd059b655, 0x58fbbed4, 0x03b88231,
499 0x034c4519, 0x194dc939, 0x1fc500ac, 0x794cc0e2, 0x3bc980a1, 0xe9b12dd1, 0x5e6d22f8, 0x7b38899a,
500 0xce7919d8, 0x78c67672, 0x79e5b99f, 0xe494034e, 0x00000001, 0xa1000000, 0x6c5cd4e9, 0x9be47d6f,
501 0xf93bd9e7, 0x77626fa1, 0xc68b3451, 0xde2b59e8, 0xcf3cde58, 0x2246ff58, 0xa8577c15, 0x26e77559,
502 0x17776753, 0xebe6b763, 0xe3fd0a5f, 0x33e83969, 0xa805a035, 0xf631b987, 0x211f0f43, 0xd85a43db,
503 0xab1bf596, 0x683f19a2, 0x00000004, 0xbe7dfe64, 0x4bc9042f, 0xe1f5edb0, 0x8fa14eda, 0xe409db73,
504 0x674fee9c, 0xa9159f0d, 0xf6b5b5d6, 0x7338960e, 0xeb49c291, 0x5f2b97cc, 0x0f383f95, 0x2091b3f6,
505 0xd1783714, 0xc1d142df, 0x153e22de, 0x8aafdf57, 0x77f5e55f, 0xa3e7ca8b, 0x032f525b, 0x42e74f3d,
506 0x0000000a, 0xf4dd1000, 0x5d450952, 0xaeb442e1, 0xa3b3342e, 0x3fcda36f, 0xb4287a6e, 0x4bc177f7,
507 0x67d2c8d0, 0xaea8f8e0, 0xadc93b67, 0x6cc856b3, 0x959d9d0b, 0x5b48c100, 0x4abe8a3d, 0x52d936f4,
508 0x71dbe84d, 0xf91c21c5, 0x4a458109, 0xd7aad86a, 0x08e14c7c, 0x759ba59c, 0xe43c8800, 0x00000017,
509 0x92400000, 0x04f110d4, 0x186472be, 0x8736c10c, 0x1478abfb, 0xfc51af29, 0x25eb9739, 0x4c2b3015,
510 0xa1030e0b, 0x28fe3c3b, 0x7788fcba, 0xb89e4358, 0x733de4a4, 0x7c46f2c2, 0x8f746298, 0xdb19210f,
511 0x2ea3b6ae, 0xaa5014b2, 0xea39ab8d, 0x97963442, 0x01dfdfa9, 0xd2f3d3fe, 0xa0790280, 0x00000037,
512 0x509c9b01, 0xc7dcadf1, 0x383dad2c, 0x73c64d37, 0xea6d67d0, 0x519ba806, 0xc403f2f8, 0xa052e1a2,
513 0xd710233a, 0x448573a9, 0xcf12d9ba, 0x70871803, 0x52dc3a9b, 0xe5b252e8, 0x0717fb4e, 0xbe4da62f,
514 0x0aabd7e1, 0x8c62ed4f, 0xceb9ec7b, 0xd4664021, 0xa1158300, 0xcce375e6, 0x842f29f2, 0x00000081,
515 0x7717e400, 0xd3f5fb64, 0xa0763d71, 0x7d142fe9, 0x33f44c66, 0xf3b8f12e, 0x130f0d8e, 0x734c9469,
516 0x60260fa8, 0x3c011340, 0xcc71880a, 0x37a52d21, 0x8adac9ef, 0x42bb31b4, 0xd6f94c41, 0xc88b056c,
517 0xe20501b8, 0x5297ed7c, 0x62c361c4, 0x87dad8aa, 0xb833eade, 0x94f06861, 0x13cc9abd, 0x8dc1d56a,
518 0x0000012d, 0x13100000, 0xc67a36e8, 0xf416299e, 0xf3493f0a, 0x77a5a6cf, 0xa4be23a3, 0xcca25b82,
519 0x3510722f, 0xbe9d447f, 0xa8c213b8, 0xc94c324e, 0xbc9e33ad, 0x76acfeba, 0x2e4c2132, 0x3e13cd32,
520 0x70fe91b4, 0xbb5cd936, 0x42149785, 0x46cc1afd, 0xe638ddf8, 0x690787d2, 0x1a02d117, 0x3eb5f1fe,
521 0xc3b9abae, 0x1c08ee6f, 0x000002be, 0x40000000, 0x8140c2aa, 0x2cf877d9, 0x71e1d73d, 0xd5e72f98,
522 0x72516309, 0xafa819dd, 0xd62a5a46, 0x2a02dcce, 0xce46ddfe, 0x2713248d, 0xb723d2ad, 0xc404bb19,
523 0xb706cc2b, 0x47b1ebca, 0x9d094bdc, 0xc5dc02ca, 0x31e6518e, 0x8ec35680, 0x342f58a8, 0x8b041e42,
524 0xfebfe514, 0x05fffc13, 0x6763790f, 0x66d536fd, 0xb9e15076, 0x00000662, 0x67b06100, 0xd2010a1a,
525 0xd005e1c0, 0xdb12733b, 0xa39f2e3f, 0x61b29de2, 0x2a63dce2, 0x942604bc, 0x6170d59b, 0xc2e32596,
526 0x140b75b9, 0x1f1d2c21, 0xb8136a60, 0x89d23ba2, 0x60f17d73, 0xc6cad7df, 0x0669df2b, 0x24b88737,
527 0x669306ed, 0x19496eeb, 0x938ddb6f, 0x5e748275, 0xc56e9a36, 0x3690b731, 0xc82842c5, 0x24ae798e,
528 0x00000ede, 0x41640000, 0xd5889ac1, 0xd9432c99, 0xa280e71a, 0x6bf63d2e, 0x8249793d, 0x79e7a943,
529 0x22fde64a, 0xe0d6709a, 0x05cacfef, 0xbd8da4d7, 0xe364006c, 0xa54edcb3, 0xa1a8086e, 0x748f459e,
530 0xfc8e54c8, 0xcc74c657, 0x42b8c3d4, 0x57d9636e, 0x35b55bcc, 0x6c13fee9, 0x1ac45161, 0xb595badb,
531 0xa1f14e9d, 0xdcf9e750, 0x07637f71, 0xde2f9f2b, 0x0000229d, 0x10000000, 0x3c5ebd89, 0xe3773756,
532 0x3dcba338, 0x81d29e4f, 0xa4f79e2c, 0xc3f9c774, 0x6a1ce797, 0xac5fe438, 0x07f38b9c, 0xd588ecfa,
533 0x3e5ac1ac, 0x85afccce, 0x9d1f3f70, 0xe82d6dd3, 0x177d180c, 0x5e69946f, 0x648e2ce1, 0x95a13948,
534 0x340fe011, 0xb4173c58, 0x2748f694, 0x7c2657bd, 0x758bda2e, 0x3b8090a0, 0x2ddbb613, 0x6dcf4890,
535 0x24e4047e, 0x00005099,
536 };
537
538 struct unpack_index
539 {
540 uint16_t _offset; // The offset of this power's initial byte in the array
541 uint8_t _zeroes; // The number of omitted leading zero elements
542 uint8_t _size; // The number of elements present for this power
543 };
544
545 static unpack_index const large_power_indices[] =
546 {
547 { 0, 0, 2 }, { 2, 0, 3 }, { 5, 0, 4 }, { 9, 1, 4 },
548 { 13, 1, 5 }, { 18, 1, 6 }, { 24, 2, 6 }, { 30, 2, 7 },
549 { 37, 2, 8 }, { 45, 3, 8 }, { 53, 3, 9 }, { 62, 3, 10 },
550 { 72, 4, 10 }, { 82, 4, 11 }, { 93, 4, 12 }, { 105, 5, 12 },
551 { 117, 5, 13 }, { 130, 5, 14 }, { 144, 5, 15 }, { 159, 6, 15 },
552 { 174, 6, 16 }, { 190, 6, 17 }, { 207, 7, 17 }, { 224, 7, 18 },
553 { 242, 7, 19 }, { 261, 8, 19 }, { 280, 8, 21 }, { 301, 8, 22 },
554 { 323, 9, 22 }, { 345, 9, 23 }, { 368, 9, 24 }, { 392, 10, 24 },
555 { 416, 10, 25 }, { 441, 10, 26 }, { 467, 10, 27 }, { 494, 11, 27 },
556 { 521, 11, 28 }, { 549, 11, 29 },
557 };
558
559 uint32_t large_power = power / 10;
560 while (large_power != 0)
561 {
562 uint32_t const current_power = large_power > _countof(large_power_indices)
563 ? _countof(large_power_indices)
564 : large_power;
565
566 unpack_index const& index = large_power_indices[current_power - 1];
567 big_integer multiplier{};
568 multiplier._used = index._size + index._zeroes;
569
570 uint32_t const* const source = large_power_data + index._offset;
571
572 memset(multiplier._data, 0, index._zeroes * sizeof(uint32_t));
573 memcpy(multiplier._data + index._zeroes, source, index._size * sizeof(uint32_t));
574
575 if (!multiply(x, multiplier))
576 {
577 x = big_integer{};
578 return false;
579 }
580
581 large_power -= current_power;
582 }
583
584 static uint32_t const small_powers_of_ten[9] =
585 {
586 10,
587 100,
588 1000,
589 1000 * 10,
590 1000 * 100,
591 1000 * 1000,
592 1000 * 1000 * 10,
593 1000 * 1000 * 100,
594 1000 * 1000 * 1000
595 };
596
597 uint32_t const small_power = power % 10;
598 if (small_power != 0)
599 {
600 if (!multiply(x, small_powers_of_ten[small_power - 1]))
601 {
602 return false;
603 }
604 }
605
606 return true;
607}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define _countof(array)
Definition: sndvol32.h:70

Referenced by accumulate_decimal_digits_into_big_integer(), convert_decimal_string_to_floating_type_common(), and convert_to_fos_high_precision().

◆ multiply_core()

__forceinline uint32_t __cdecl __crt_strtox::multiply_core ( _Inout_updates_all_(multiplicand_count) uint32_t *const  multiplicand,
uint32_t const  multiplicand_count,
uint32_t const  multiplier 
)
throw (
)

Definition at line 311 of file corecrt_internal_big_integer.h.

316{
317 uint32_t carry = 0;
318 for (uint32_t i = 0; i != multiplicand_count; ++i)
319 {
320 uint64_t const result = static_cast<uint64_t>(multiplicand[i]) * multiplier + carry;
321 multiplicand[i] = static_cast<uint32_t>(result);
322 carry = static_cast<uint32_t>(result >> 32);
323 }
324
325 return carry;
326}

Referenced by multiply().

◆ operator!=()

__forceinline bool __cdecl __crt_strtox::operator!= ( big_integer const lhs,
big_integer const rhs 
)
throw (
)

Definition at line 99 of file corecrt_internal_big_integer.h.

100{
101 return !(rhs == lhs);
102}

◆ operator<()

__forceinline bool __cdecl __crt_strtox::operator< ( big_integer const lhs,
big_integer const rhs 
)
throw (
)

Definition at line 104 of file corecrt_internal_big_integer.h.

105{
106 if (lhs._used > rhs._used)
107 return false;
108
109 if (lhs._used < rhs._used)
110 return true;
111
112 uint32_t i = lhs._used - 1;
113 for (; i != static_cast<uint32_t>(-1) && lhs._data[i] == rhs._data[i]; --i)
114 {
115 // No-op
116 }
117
118 if (i == static_cast<uint32_t>(-1))
119 return false;
120
121 if (lhs._data[i] <= rhs._data[i])
122 return true;
123
124 return false;
125}

◆ operator==()

__forceinline bool __cdecl __crt_strtox::operator== ( big_integer const lhs,
big_integer const rhs 
)
throw (
)

Definition at line 85 of file corecrt_internal_big_integer.h.

86{
87 if (lhs._used != rhs._used)
88 return false;
89
90 for (uint32_t i = 0; i != lhs._used; ++i)
91 {
92 if (lhs._data[i] != rhs._data[i])
93 return false;
94 }
95
96 return true;
97}

◆ operator>=()

__forceinline bool __cdecl __crt_strtox::operator>= ( big_integer const lhs,
big_integer const rhs 
)
throw (
)

Definition at line 127 of file corecrt_internal_big_integer.h.

128{
129 return !(lhs < rhs);
130}

◆ parse_digit() [1/2]

__forceinline unsigned __cdecl __crt_strtox::parse_digit ( char const  c)
throw (
)

Definition at line 128 of file corecrt_internal_strtox.h.

129{
130 if (c >= '0' && c <= '9')
131 {
132 return static_cast<unsigned>(c - '0');
133 }
134
135 if (c >= 'a' && c <= 'z')
136 {
137 return static_cast<unsigned>(c - 'a' + 10);
138 }
139
140 if (c >= 'A' && c <= 'Z')
141 {
142 return static_cast<unsigned>(c - 'A' + 10);
143 }
144
145 return static_cast<unsigned>(-1);
146}

Referenced by parse_floating_point_from_source(), parse_integer(), and __crt_stdio_input::format_string_parser< Character >::scan_optional_field_width().

◆ parse_digit() [2/2]

__forceinline unsigned __cdecl __crt_strtox::parse_digit ( wchar_t const  c)
throw (
)

Definition at line 148 of file corecrt_internal_strtox.h.

149{
150 int const value = wide_character_to_digit(c);
151 if (value != -1)
152 return static_cast<unsigned>(value);
153
154 if (__ascii_iswalpha(c))
155 return static_cast<unsigned>(__ascii_towupper(c) - 'A' + 10);
156
157 return static_cast<unsigned>(-1);
158}
__forceinline int __CRTDECL __ascii_iswalpha(int const _C)
Definition: ctype.h:170
__forceinline int __CRTDECL __ascii_towupper(int const _C)
Definition: ctype.h:185
__forceinline int __cdecl wide_character_to_digit(wchar_t const c)

◆ parse_floating_point()

template<typename CharacterSource , typename FloatingType >
SLD_STATUS __cdecl __crt_strtox::parse_floating_point ( _locale_t const  locale,
CharacterSource  source,
FloatingType *const  result 
)
throw (
)

Definition at line 1754 of file corecrt_internal_strtox.h.

1759{
1760 using char_type = typename CharacterSource::char_type;
1761
1764
1765 // PERFORMANCE NOTE: fp_string is intentionally left uninitialized. Zero-
1766 // initialization is quite expensive and is unnecessary. The benefit of not
1767 // zero-initializing is greatest for short inputs.
1768 floating_point_string fp_string;
1769
1771
1772 return parse_floating_point_write_result(parse_result, fp_string, result);
1773}
#define EINVAL
Definition: acclib.h:90
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
floating_point_parse_result __cdecl parse_floating_point_from_source(_locale_t const locale, CharacterSource &source, floating_point_string &fp_string)
SLD_STATUS __cdecl parse_floating_point_write_result(floating_point_parse_result const parse_result, floating_point_string const &fp_string, FloatingType *const result)

Referenced by _atoldbl_l(), common_atodbl_l(), common_atof_l(), common_strtod_l(), and __crt_stdio_input::input_processor< Character, InputAdapter >::process_floating_point_specifier_t().

◆ parse_floating_point_from_source()

template<typename CharacterSource >
floating_point_parse_result __cdecl __crt_strtox::parse_floating_point_from_source ( _locale_t const  locale,
CharacterSource &  source,
floating_point_string fp_string 
)
throw (
)

Definition at line 1402 of file corecrt_internal_strtox.h.

1407{
1408 using char_type = typename CharacterSource::char_type;
1409
1410 if (!source.validate())
1411 {
1412 return floating_point_parse_result::no_digits;
1413 }
1414
1415 auto stored_state = source.save_state();
1416 char_type c{source.get()};
1417
1418 auto restore_state = [&]()
1419 {
1420 source.unget(c);
1421 c = '\0';
1422 return source.restore_state(stored_state);
1423 };
1424
1425 // Skip past any leading whitespace:
1426 while (is_space(c, locale))
1427 {
1428 c = source.get();
1429 }
1430
1431 // Check for the optional plus or minus sign:
1432 fp_string._is_negative = c == '-';
1433 if (c == '-' || c == '+')
1434 {
1435 c = source.get();
1436 }
1437
1438 // Handle special cases "INF" and "INFINITY" (these are the only accepted
1439 // character sequences that start with 'I'):
1440 if (c == 'I' || c == 'i')
1441 {
1442 return parse_floating_point_possible_infinity(c, source, stored_state);
1443 }
1444
1445 // Handle special cases "NAN" and "NAN(...)" (these are the only accepted
1446 // character sequences that start with 'N'):
1447 if (c == 'N' || c == 'n')
1448 {
1449 return parse_floating_point_possible_nan(c, source, stored_state);
1450 }
1451
1452 // Check for optional "0x" or "0X" hexadecimal base prefix:
1453 bool is_hexadecimal{false};
1454 if (c == '0')
1455 {
1456 auto const next_stored_state = source.save_state();
1457
1458 char_type const next_c{source.get()};
1459 if (next_c == 'x' || next_c == 'X')
1460 {
1461 is_hexadecimal = true;
1462 c = source.get();
1463
1464 // If we match the hexadecimal base prefix we update the state to
1465 // reflect that we consumed the leading zero to handle the case
1466 // where a valid mantissa does not follow the base prefix. In this
1467 // case, the "0x" string is treated as a decimal zero subject ("0")
1468 // followed by a final string starting with the "x".
1469 stored_state = next_stored_state;
1470 }
1471 else
1472 {
1473 source.unget(next_c);
1474 }
1475 }
1476
1477 uint8_t* mantissa_first{fp_string._mantissa};
1478 uint8_t* const mantissa_last {fp_string._mantissa + _countof(fp_string._mantissa)};
1479 uint8_t* mantissa_it {fp_string._mantissa};
1480
1481 // The exponent adjustment holds the number of digits in the mantissa buffer
1482 // that appeared before the radix point. It is positive for number strings
1483 // with an integer component and negative for number strings without.
1484 int exponent_adjustment{0};
1485
1486 // Track whether we've seen any digits, so we know whether we've successfully
1487 // parsed something:
1488 bool found_digits{false};
1489
1490 // Skip past any leading zeroes in the mantissa:
1491 while (c == '0')
1492 {
1493 found_digits = true;
1494 c = source.get();
1495 }
1496
1497 // Scan the integer part of the mantissa:
1498 for (; ; c = source.get())
1499 {
1500 unsigned const max_digit_value{is_hexadecimal ? 0xfu : 9u};
1501
1502 unsigned const digit_value{parse_digit(c)};
1503 if (digit_value > max_digit_value)
1504 {
1505 break;
1506 }
1507
1508 found_digits = true;
1509 if (mantissa_it != mantissa_last)
1510 {
1511 *mantissa_it++ = static_cast<uint8_t>(digit_value);
1512 }
1513
1514 ++exponent_adjustment;
1515 }
1516
1517 // If a radix point is present, scan the fractional part of the mantissa:
1518 char const radix_point{*locale->locinfo->lconv->decimal_point};
1519 if (c == radix_point)
1520 {
1521 c = source.get();
1522
1523 // If we haven't yet scanned any nonzero digits, continue skipping over
1524 // zeroes, updating the exponent adjustment to account for the zeroes
1525 // we are skipping:
1526 if (mantissa_it == mantissa_first)
1527 {
1528 while (c == '0')
1529 {
1530 found_digits = true;
1531 --exponent_adjustment;
1532 c = source.get();
1533 }
1534 }
1535
1536 for (; ; c = source.get())
1537 {
1538 unsigned const max_digit_value{is_hexadecimal ? 0xfu : 9u};
1539
1540 unsigned const digit_value{parse_digit(c)};
1541 if (digit_value > max_digit_value)
1542 break;
1543
1544 found_digits = true;
1545 if (mantissa_it != mantissa_last)
1546 {
1547 *mantissa_it++ = static_cast<uint8_t>(digit_value);
1548 }
1549 }
1550 }
1551
1552 if (!found_digits)
1553 {
1554 // We failed to parse any digits, so attempt to restore back to the last
1555 // good terminal state. This may fail if we are reading from a stream,
1556 // we read a hexadecimal base prefix ("0x"), but we did not find any digits
1557 // following the base prefix.
1558 if (!restore_state())
1559 {
1560 return floating_point_parse_result::no_digits;
1561 }
1562
1563 // If a hexadecimal base prefix was present ("0x"), then the string is a
1564 // valid input: the "0" is the subject sequence and the "x" is the first
1565 // character of the final string. Otherwise, the string is not a valid
1566 // input.
1567 if (is_hexadecimal)
1568 {
1569 return floating_point_parse_result::zero;
1570 }
1571 else
1572 {
1573 return floating_point_parse_result::no_digits;
1574 }
1575 }
1576
1577 source.unget(c);
1578 stored_state = source.save_state();
1579 c = source.get();
1580
1581 // Check for the optional 'e' or 'p' exponent introducer:
1582 bool has_exponent{false};
1583 switch (c)
1584 {
1585 case 'e':
1586 case 'E':
1587 has_exponent = !is_hexadecimal;
1588 break;
1589
1590 case 'p':
1591 case 'P':
1592 has_exponent = is_hexadecimal;
1593 break;
1594 }
1595
1596 // If there was an exponent introducer, scan the exponent:
1597 int exponent{0};
1598 if (has_exponent)
1599 {
1600 c = source.get(); // Skip past exponent introducer character
1601
1602 // Check for the optional plus or minus sign:
1603 bool const exponent_is_negative{c == '-'};
1604 if (c == '+' || c == '-')
1605 {
1606 c = source.get();
1607 }
1608
1609 bool has_exponent_digits{false};
1610
1611 while (c == '0')
1612 {
1613 has_exponent_digits = true;
1614 c = source.get();
1615 }
1616
1617 for (; ; c = source.get())
1618 {
1619 unsigned const digit_value{parse_digit(c)};
1620 if (digit_value >= 10)
1621 {
1622 break;
1623 }
1624
1625 has_exponent_digits = true;
1626 exponent = exponent * 10 + digit_value;
1627 if (exponent > maximum_temporary_decimal_exponent)
1628 {
1630 break;
1631 }
1632 }
1633
1634 // If the exponent is too large, skip over the remaining exponent digits
1635 // so we can correctly update the end pointer:
1636 while (parse_digit(c) < 10)
1637 {
1638 c = source.get();
1639 }
1640
1641 if (exponent_is_negative)
1642 {
1643 exponent = -exponent;
1644 }
1645
1646 // If no exponent digits were present, attempt to restore the last good
1647 // terminal state.
1648 if (!has_exponent_digits)
1649 {
1650 if (restore_state())
1651 {
1652 // The call to restore_state will have ungotten the exponent
1653 // introducer. Re-get this character, to restore us to the
1654 // state we had before we entered the exponent parsing block.
1655 c = source.get();
1656 }
1657 else
1658 {
1659 return floating_point_parse_result::no_digits;
1660 }
1661 }
1662 }
1663
1664 // Unget the last character that we read that terminated input. After this
1665 // point, we must not use the source, c, or stored_state.
1666 source.unget(c);
1667
1668 // Remove trailing zeroes from mantissa:
1669 while (mantissa_it != mantissa_first && *(mantissa_it - 1) == 0)
1670 {
1671 --mantissa_it;
1672 }
1673
1674 // If the mantissa buffer is empty, the mantissa was composed of all zeroes
1675 // (so the mantissa is 0). All such strings have the value zero, regardless
1676 // what the exponent is (because 0 x b^n == 0 for all b and n). We can return
1677 // now. Note that we defer this check until after we scan the exponent, so
1678 // that we can correctly update end_ptr to point past the end of the exponent.
1679 if (mantissa_it == mantissa_first)
1680 {
1681 return floating_point_parse_result::zero;
1682 }
1683
1684 // Before we adjust the exponent, handle the case where we detected a wildly
1685 // out of range exponent during parsing and clamped the value:
1686 if (exponent > maximum_temporary_decimal_exponent)
1687 {
1688 return floating_point_parse_result::overflow;
1689 }
1690
1691 if (exponent < minimum_temporary_decimal_exponent)
1692 {
1693 return floating_point_parse_result::underflow;
1694 }
1695
1696 // In hexadecimal floating constants, the exponent is a base 2 exponent. The
1697 // exponent adjustment computed during parsing has the same base as the
1698 // mantissa (so, 16 for hexadecimal floating constants). We therefore need to
1699 // scale the base 16 multiplier to base 2 by multiplying by log2(16):
1700 int const exponent_adjustment_multiplier{is_hexadecimal ? 4 : 1};
1701
1702 exponent += exponent_adjustment * exponent_adjustment_multiplier;
1703
1704 // Verify that after adjustment the exponent isn't wildly out of range (if
1705 // it is, it isn't representable in any supported floating point format).
1706 if (exponent > maximum_temporary_decimal_exponent)
1707 {
1708 return floating_point_parse_result::overflow;
1709 }
1710
1711 if (exponent < minimum_temporary_decimal_exponent)
1712 {
1713 return floating_point_parse_result::underflow;
1714 }
1715
1716 fp_string._exponent = exponent;
1717 fp_string._mantissa_count = static_cast<uint32_t>(mantissa_it - mantissa_first);
1718
1719 return is_hexadecimal
1720 ? floating_point_parse_result::hexadecimal_digits
1721 : floating_point_parse_result::decimal_digits;
1722}
#define is_space(c)
Definition: astoll.c:38
floating_point_parse_result __cdecl parse_floating_point_possible_infinity(Character &c, CharacterSource &source, StoredState stored_state)
floating_point_parse_result __cdecl parse_floating_point_possible_nan(Character &c, CharacterSource &source, StoredState stored_state)
__forceinline unsigned __cdecl parse_digit(char const c)

Referenced by parse_floating_point().

◆ parse_floating_point_possible_infinity()

template<typename Character , typename CharacterSource , typename StoredState >
floating_point_parse_result __cdecl __crt_strtox::parse_floating_point_possible_infinity ( Character &  c,
CharacterSource &  source,
StoredState  stored_state 
)
throw (
)

Definition at line 1286 of file corecrt_internal_strtox.h.

1291{
1292 using char_type = typename CharacterSource::char_type;
1293
1294 auto restore_state = [&]()
1295 {
1296 source.unget(c);
1297 c = '\0';
1298 return source.restore_state(stored_state);
1299 };
1300
1301 static char_type const inf_uppercase[] = { 'I', 'N', 'F' };
1302 static char_type const inf_lowercase[] = { 'i', 'n', 'f' };
1303 if (!parse_next_characters_from_source(inf_uppercase, inf_lowercase, _countof(inf_uppercase), c, source))
1304 {
1305 return restore_state(), floating_point_parse_result::no_digits;
1306 }
1307
1308 source.unget(c);
1309 stored_state = source.save_state();
1310 c = source.get();
1311
1312 static char_type const inity_uppercase[] = { 'I', 'N', 'I', 'T', 'Y' };
1313 static char_type const inity_lowercase[] = { 'i', 'n', 'i', 't', 'y' };
1314 if (!parse_next_characters_from_source(inity_uppercase, inity_lowercase, _countof(inity_uppercase), c, source))
1315 {
1316 return restore_state()
1317 ? floating_point_parse_result::infinity
1318 : floating_point_parse_result::no_digits;
1319 }
1320
1321 source.unget(c);
1322 return floating_point_parse_result::infinity;
1323}
bool __cdecl parse_next_characters_from_source(Character const *const uppercase, Character const *const lowercase, size_t const count, Character &c, CharacterSource &source)

Referenced by parse_floating_point_from_source().

◆ parse_floating_point_possible_nan()

template<typename Character , typename CharacterSource , typename StoredState >
floating_point_parse_result __cdecl __crt_strtox::parse_floating_point_possible_nan ( Character &  c,
CharacterSource &  source,
StoredState  stored_state 
)
throw (
)

Definition at line 1326 of file corecrt_internal_strtox.h.

1331{
1332 using char_type = typename CharacterSource::char_type;
1333
1334 auto restore_state = [&]()
1335 {
1336 source.unget(c);
1337 c = '\0';
1338 return source.restore_state(stored_state);
1339 };
1340
1341 static char_type const uppercase[] = { 'N', 'A', 'N' };
1342 static char_type const lowercase[] = { 'n', 'a', 'n' };
1344 {
1345 return restore_state(), floating_point_parse_result::no_digits;
1346 }
1347
1348 source.unget(c);
1349 stored_state = source.save_state();
1350 c = source.get();
1351
1352 if (c != '(')
1353 {
1354 return restore_state()
1355 ? floating_point_parse_result::qnan
1356 : floating_point_parse_result::no_digits;
1357 }
1358
1359 c = source.get(); // Advance past the left parenthesis
1360
1361 // After we've parsed a left parenthesis, test to see whether the parenthesized
1362 // string represents a signaling NaN "(SNAN)" or an indeterminate "(IND)". If
1363 // so, we return the corresponding kind of NaN:
1365 {
1366 source.unget(c);
1367 return floating_point_parse_result::snan;
1368 }
1369
1371 {
1372 source.unget(c);
1373 return floating_point_parse_result::indeterminate;
1374 }
1375
1376 // Otherwise, we didn't match one of the two special parenthesized strings.
1377 // Keep eating chracters until we come across the right parenthesis or the
1378 // end of the character sequence:
1379 while (c != ')' && c != '\0')
1380 {
1381 if (!is_digit_or_nondigit(c))
1382 {
1383 return restore_state()
1384 ? floating_point_parse_result::qnan
1385 : floating_point_parse_result::no_digits;
1386 }
1387
1388 c = source.get();
1389 }
1390
1391 if (c != ')')
1392 {
1393 return restore_state()
1394 ? floating_point_parse_result::qnan
1395 : floating_point_parse_result::no_digits;
1396 }
1397
1398 return floating_point_parse_result::qnan;
1399}
ios_base &_STLP_CALL uppercase(ios_base &__s)
Definition: _ios_base.h:297
bool __cdecl parse_floating_point_possible_nan_is_ind(Character &c, CharacterSource &source)
__forceinline bool __cdecl is_digit_or_nondigit(int const c)
bool __cdecl parse_floating_point_possible_nan_is_snan(Character &c, CharacterSource &source)

Referenced by parse_floating_point_from_source().

◆ parse_floating_point_possible_nan_is_ind()

template<typename Character , typename CharacterSource >
bool __cdecl __crt_strtox::parse_floating_point_possible_nan_is_ind ( Character &  c,
CharacterSource &  source 
)
throw (
)

Definition at line 1275 of file corecrt_internal_strtox.h.

1279{
1280 static Character const uppercase[] = { 'I', 'N', 'D', ')' };
1281 static Character const lowercase[] = { 'i', 'n', 'd', ')' };
1283}

Referenced by parse_floating_point_possible_nan().

◆ parse_floating_point_possible_nan_is_snan()

template<typename Character , typename CharacterSource >
bool __cdecl __crt_strtox::parse_floating_point_possible_nan_is_snan ( Character &  c,
CharacterSource &  source 
)
throw (
)

Definition at line 1264 of file corecrt_internal_strtox.h.

1268{
1269 static Character const uppercase[] = { 'S', 'N', 'A', 'N', ')' };
1270 static Character const lowercase[] = { 's', 'n', 'a', 'n', ')' };
1272}

Referenced by parse_floating_point_possible_nan().

◆ parse_floating_point_write_result()

template<typename FloatingType >
SLD_STATUS __cdecl __crt_strtox::parse_floating_point_write_result ( floating_point_parse_result const  parse_result,
floating_point_string const fp_string,
FloatingType *const  result 
)
throw (
)

Definition at line 1725 of file corecrt_internal_strtox.h.

1730{
1731 switch (parse_result)
1732 {
1733 case floating_point_parse_result::decimal_digits: return convert_decimal_string_to_floating_type (fp_string, *result);
1734 case floating_point_parse_result::hexadecimal_digits: return convert_hexadecimal_string_to_floating_type(fp_string, *result);
1735
1736 case floating_point_parse_result::zero: assemble_floating_point_zero (fp_string._is_negative, *result); return SLD_OK;
1737 case floating_point_parse_result::infinity: assemble_floating_point_infinity(fp_string._is_negative, *result); return SLD_OK;
1738 case floating_point_parse_result::qnan: assemble_floating_point_qnan (fp_string._is_negative, *result); return SLD_OK;
1739 case floating_point_parse_result::snan: assemble_floating_point_snan (fp_string._is_negative, *result); return SLD_OK;
1740 case floating_point_parse_result::indeterminate: assemble_floating_point_ind ( *result); return SLD_OK;
1741
1742 case floating_point_parse_result::no_digits: assemble_floating_point_zero (false, *result); return SLD_NODIGITS;
1743 case floating_point_parse_result::underflow: assemble_floating_point_zero (fp_string._is_negative, *result); return SLD_UNDERFLOW;
1744 case floating_point_parse_result::overflow: assemble_floating_point_infinity(fp_string._is_negative, *result); return SLD_OVERFLOW;
1745
1746 default:
1747 // Unreachable
1748 _ASSERTE(false);
1749 return SLD_NODIGITS;
1750 }
1751}
SLD_STATUS __cdecl convert_hexadecimal_string_to_floating_type(floating_point_string const &data, _LDBL12 &result)
Definition: atoldbl.cpp:652
SLD_STATUS __cdecl convert_decimal_string_to_floating_type(floating_point_string const &data, _LDBL12 &result)
Definition: atoldbl.cpp:644

Referenced by parse_floating_point().

◆ parse_integer() [1/2]

template<typename UnsignedInteger , typename CharacterSource , bool TrimWhitespace = true>
UnsignedInteger __cdecl __crt_strtox::parse_integer ( __crt_cached_ptd_host &  ptd,
CharacterSource  source,
int  base,
bool const  is_result_signed 
)
throw (
)

Definition at line 223 of file corecrt_internal_strtox.h.

229{
230 static_assert(!__crt_strtox::is_signed<UnsignedInteger>::value, "UnsignedInteger must be unsigned");
231
232 using char_type = typename CharacterSource::char_type;
233
234 if (!source.validate())
235 return 0;
236
237 _UCRT_VALIDATE_RETURN(ptd, base == 0 || (2 <= base && base <= 36), EINVAL, 0);
238 UnsignedInteger number{0}; // number is the accumulator
239
240 auto const initial_state = source.save_state();
241
242
243 char_type c{source.get()};
244
245 if constexpr (TrimWhitespace)
246 {
247 const _locale_t loc = ptd.get_locale();
248 while (is_space(c, loc))
249 {
250 c = source.get();
251 }
252 }
253
254 unsigned flags{is_result_signed ? FL_SIGNED : 0};
255
256 // Optional sign (+ or -):
257 if (c == '-')
258 {
260 }
261
262 if (c == '-' || c == '+')
263 {
264 c = source.get();
265 }
266
267 // If the base is zero, we try to detect the base from the string prefix:
268 if (base == 0 || base == 16)
269 {
270 if (parse_digit(c) != 0)
271 {
272 if (base == 0)
273 {
274 base = 10;
275 }
276 }
277 else
278 {
279 char_type const next_c = source.get();
280 if (next_c == 'x' || next_c == 'X')
281 {
282 if (base == 0)
283 {
284 base = 16;
285 }
286 c = source.get();
287 }
288 else
289 {
290 if (base == 0)
291 {
292 base = 8;
293 }
294 source.unget(next_c);
295 }
296 }
297 }
298
299 UnsignedInteger const max_pre_multiply_value = static_cast<UnsignedInteger>(-1) / base;
300
301 for (;;)
302 {
303 unsigned const digit{parse_digit(c)};
304 if (digit >= static_cast<unsigned>(base))
305 {
306 // This also handles the case where the digit could not
307 // be parsed and parse_digit returns -1.
308 break;
309 }
310
312
313 UnsignedInteger const number_after_multiply = number * base;
314 UnsignedInteger const number_after_add = number_after_multiply + digit;
315
316 // Avoid branching when setting overflow flag.
317 flags |= FL_OVERFLOW * ((number > max_pre_multiply_value) | (number_after_add < number_after_multiply));
318
319 number = number_after_add;
320
321 c = source.get();
322 }
323
324 source.unget(c); // Return the pointer to the character that ended the scan
325
326 // If we failed to read any digits, there's no number to be read:
327 if ((flags & FL_READ_DIGIT) == 0)
328 {
329 source.restore_state(initial_state);
330 return 0;
331 }
332
334 {
335 ptd.get_errno().set(ERANGE);
336
337 if ((flags & FL_SIGNED) == 0)
338 {
339 number = static_cast<UnsignedInteger>(-1);
340 }
341 else if (flags & FL_NEGATIVE)
342 {
343 return minimum_signed_value(UnsignedInteger());
344 }
345 else
346 {
347 return maximum_signed_value(UnsignedInteger());
348 }
349 }
350 else if (flags & FL_NEGATIVE)
351 {
352 number = static_cast<UnsignedInteger>(-static_cast<typename make_signed<UnsignedInteger>::type>(number));
353 }
354
355 return number;
356}
#define ERANGE
Definition: acclib.h:92
#define _UCRT_VALIDATE_RETURN(ptd, expr, errorcode, retexpr)
_In_ size_t const _In_ int _In_ bool const _In_ unsigned const _In_ __acrt_rounding_mode const _Inout_ __crt_cached_ptd_host & ptd
Definition: cvt.cpp:355
char typename[32]
Definition: main.c:84
bool is_overflow_condition(unsigned const flags, UnsignedInteger const number)

◆ parse_integer() [2/2]

template<typename UnsignedInteger , typename CharacterSource >
UnsignedInteger __cdecl __crt_strtox::parse_integer ( _locale_t const  locale,
CharacterSource  source,
int  base,
bool const  is_result_signed 
)
throw (
)

Definition at line 359 of file corecrt_internal_strtox.h.

365{
366 __crt_cached_ptd_host ptd{locale};
367 return parse_integer<UnsignedInteger>(ptd, static_cast<CharacterSource&&>(source), base, is_result_signed);
368}

◆ parse_integer_from_string()

template<typename Integer , typename Character , typename EndPointer >
__forceinline Integer __cdecl __crt_strtox::parse_integer_from_string ( Character const *const  string,
EndPointer const  end,
int const  base,
_locale_t const  locale 
)
throw (
)

Definition at line 1877 of file corecrt_internal_strtox.h.

1883{
1884 __crt_cached_ptd_host ptd{locale};
1885
1886 return static_cast<Integer>(parse_integer<typename make_unsigned<Integer>::type>(
1887 ptd,
1888 make_c_string_character_source(string, end),
1889 base,
1890 is_signed<Integer>::value));
1891}

◆ parse_next_characters_from_source()

template<typename Character , typename CharacterSource >
bool __cdecl __crt_strtox::parse_next_characters_from_source ( Character const *const  uppercase,
Character const *const  lowercase,
size_t const  count,
Character &  c,
CharacterSource &  source 
)
throw (
)

Definition at line 1242 of file corecrt_internal_strtox.h.

1249{
1250 for (size_t i = 0; i != count; ++i)
1251 {
1252 if (c != uppercase[i] && c != lowercase[i])
1253 {
1254 return false;
1255 }
1256
1257 c = source.get();
1258 }
1259
1260 return true;
1261}
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by parse_floating_point_possible_infinity(), parse_floating_point_possible_nan(), parse_floating_point_possible_nan_is_ind(), and parse_floating_point_possible_nan_is_snan().

◆ right_shift_with_rounding()

__forceinline uint64_t __cdecl __crt_strtox::right_shift_with_rounding ( bool const  is_negative,
uint64_t const  value,
uint32_t const  shift,
bool const  has_zero_tail 
)
throw (
)

Definition at line 676 of file corecrt_internal_strtox.h.

682{
683 // If we'd need to shift further than it is possible to shift, the answer
684 // is always zero:
685 if (shift >= sizeof(uint64_t) * CHAR_BIT)
686 {
687 return 0;
688 }
689
690 uint64_t const extra_bits_mask = (1ull << (shift - 1)) - 1;
691 uint64_t const round_bit_mask = (1ull << (shift - 1));
692 uint64_t const lsb_bit_mask = 1ull << shift;
693
694 bool const lsb_bit = (value & lsb_bit_mask) != 0;
695 bool const round_bit = (value & round_bit_mask) != 0;
696 bool const tail_bits = !has_zero_tail || (value & extra_bits_mask) != 0;
697
698 return (value >> shift) + should_round_up(is_negative, lsb_bit, round_bit, tail_bits);
699}
static bool should_round_up(char const *const mantissa_base, char const *const mantissa_it, int const sign, __acrt_has_trailing_digits const trailing_digits, __acrt_rounding_mode const rounding_mode)
Definition: _fptostr.cpp:43
#define CHAR_BIT
Definition: urlcache.c:62

Referenced by assemble_floating_point_value().

◆ shift_left()

__forceinline bool __cdecl __crt_strtox::shift_left ( big_integer x,
uint32_t const  n 
)
throw (
)

Definition at line 195 of file corecrt_internal_big_integer.h.

196{
197 uint32_t const unit_shift = n / big_integer::element_bits;
198 uint32_t const bit_shift = n % big_integer::element_bits;
199
200 uint64_t const one = 1;
201
202 uint32_t const msb_bits = bit_shift;
203 uint32_t const lsb_bits = big_integer::element_bits - msb_bits;
204
205 uint32_t const lsb_mask = static_cast<uint32_t>((one << lsb_bits) - one);
206 uint32_t const msb_mask = ~lsb_mask;
207
208 bool const bit_shifts_into_next_unit = bit_shift > (big_integer::element_bits - bit_scan_reverse(x._data[x._used - 1]));
209
210 bool const unit_shift_will_overflow = x._used + unit_shift > big_integer::element_count;
211
212 if (unit_shift_will_overflow)
213 {
214 x = big_integer{};
215 return false;
216 }
217
218 uint32_t const new_used =
219 x._used + unit_shift + static_cast<uint32_t>(bit_shifts_into_next_unit);
220
221 if (new_used > big_integer::element_count)
222 {
223 x = big_integer{};
224 return false;
225 }
226
227 for (uint32_t destination_index = new_used - 1; destination_index != unit_shift - 1; --destination_index)
228 {
229 uint32_t const upper_source_index = destination_index - unit_shift;
230 uint32_t const lower_source_index = destination_index - unit_shift - 1;
231
232 uint32_t const upper_source = upper_source_index < x._used ? x._data[upper_source_index] : 0;
233 uint32_t const lower_source = lower_source_index < x._used ? x._data[lower_source_index] : 0;
234
235 uint32_t const shifted_upper_source = (upper_source & lsb_mask) << msb_bits;
236 uint32_t const shifted_lower_source = (lower_source & msb_mask) >> lsb_bits;
237
238 uint32_t const combined_shifted_source = shifted_upper_source | shifted_lower_source;
239
240 x._data[destination_index] = combined_shifted_source;
241 }
242
243 for (uint32_t destination_index = 0; destination_index != unit_shift; ++destination_index)
244 {
245 x._data[destination_index] = 0;
246 }
247
248 x._used = new_used;
249
250 return true;
251}
GLdouble n
Definition: glext.h:7729

Referenced by convert_decimal_string_to_floating_type_common(), and convert_to_fos_high_precision().

◆ should_round_up()

__forceinline bool __cdecl __crt_strtox::should_round_up ( bool const  is_negative,
bool const  lsb_bit,
bool const  round_bit,
bool const  has_tail_bits 
)
throw (
)

Definition at line 639 of file corecrt_internal_strtox.h.

645{
646 // If there are no insignificant set bits, the value is exactly representable
647 // and should not be rounded in any rounding mode:
648 bool const is_exactly_representable = !round_bit && !has_tail_bits;
649 if (is_exactly_representable)
650 {
651 return false;
652 }
653
654 // If there are insignificant set bits, we need to round according to the
655 // current rounding mode. For FE_TONEAREST, we need to handle two cases:
656 // we round up if either [1] the value is slightly greater than the midpoint
657 // between two exactly representable values or [2] the value is exactly the
658 // midpoint between two exactly representable values and the greater of the
659 // two is even (this is "round-to-even").
660 switch (fegetround())
661 {
662 case FE_TONEAREST: return round_bit && (has_tail_bits || lsb_bit);
663 case FE_UPWARD: return !is_negative;
664 case FE_DOWNWARD: return is_negative;
665 case FE_TOWARDZERO: return false;
666 }
667
668 _ASSERTE(("unexpected rounding mode", false));
669 return false;
670}
#define FE_UPWARD
Definition: fenv.h:22
#define FE_TONEAREST
Definition: fenv.h:20
#define FE_DOWNWARD
Definition: fenv.h:21
int __cdecl fegetround(void)
#define FE_TOWARDZERO
Definition: fenv.h:23

Referenced by right_shift_with_rounding().

◆ wide_character_to_digit()

__forceinline int __cdecl __crt_strtox::wide_character_to_digit ( wchar_t const  c)
throw (
)

Definition at line 88 of file corecrt_internal_strtox.h.

89{
90 #define DIGIT_RANGE_TEST(zero) \
91 if (c < zero) \
92 return -1; \
93 \
94 if (c < zero + 10) \
95 return c - zero;
96
97 DIGIT_RANGE_TEST(0x0030) // 0030;DIGIT ZERO
98 if (c < 0xFF10) // FF10;FULLWIDTH DIGIT ZERO
99 {
100 DIGIT_RANGE_TEST(0x0660) // 0660;ARABIC-INDIC DIGIT ZERO
101 DIGIT_RANGE_TEST(0x06F0) // 06F0;EXTENDED ARABIC-INDIC DIGIT ZERO
102 DIGIT_RANGE_TEST(0x0966) // 0966;DEVANAGARI DIGIT ZERO
103 DIGIT_RANGE_TEST(0x09E6) // 09E6;BENGALI DIGIT ZERO
104 DIGIT_RANGE_TEST(0x0A66) // 0A66;GURMUKHI DIGIT ZERO
105 DIGIT_RANGE_TEST(0x0AE6) // 0AE6;GUJARATI DIGIT ZERO
106 DIGIT_RANGE_TEST(0x0B66) // 0B66;ORIYA DIGIT ZERO
107 DIGIT_RANGE_TEST(0x0C66) // 0C66;TELUGU DIGIT ZERO
108 DIGIT_RANGE_TEST(0x0CE6) // 0CE6;KANNADA DIGIT ZERO
109 DIGIT_RANGE_TEST(0x0D66) // 0D66;MALAYALAM DIGIT ZERO
110 DIGIT_RANGE_TEST(0x0E50) // 0E50;THAI DIGIT ZERO
111 DIGIT_RANGE_TEST(0x0ED0) // 0ED0;LAO DIGIT ZERO
112 DIGIT_RANGE_TEST(0x0F20) // 0F20;TIBETAN DIGIT ZERO
113 DIGIT_RANGE_TEST(0x1040) // 1040;MYANMAR DIGIT ZERO
114 DIGIT_RANGE_TEST(0x17E0) // 17E0;KHMER DIGIT ZERO
115 DIGIT_RANGE_TEST(0x1810) // 1810;MONGOLIAN DIGIT ZERO
116
117 return -1;
118 }
119
120 #undef DIGIT_RANGE_TEST
121
122 if (c < 0xFF10 + 10) // FF10;FULLWIDTH DIGIT ZERO
123 return c - 0xFF10;
124
125 return -1;
126}
return
Definition: dirsup.c:529
#define DIGIT_RANGE_TEST(zero)
if(dx< 0)
Definition: linetemp.h:194

Referenced by parse_digit().