102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
floating_point.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
9#include <intrin.h>
10#include <math.h>
11#include <stdarg.h>
12#include <string.h>
13#define nullptr 0
14
15// Original pcdogs.exe: 0x445ed6
16// Installs floating-point formatting support, records the processor division-erratum result, sets default precision, and clears pending x87 exceptions.
24
25// Original pcdogs.exe: 0x445eee
26// Installs the CRT floating-point formatting and assignment callback table.
36
37// Original pcdogs.exe: 0x445f28
38// Converts a floating-point value to a signed 64-bit integer by truncation. The native helper consumes an x87 stack value and returns the integer through EDX:EAX.
39int64_t __ftol_msvc(long double value)
40{
41 int64_t result;
42 uint16_t saved_control, truncating_control;
43
44 /* The C adapter loads its long-double argument into ST0. Keep the native
45 FISTP conversion, including integer-indefinite and exception semantics. */
46 __asm__ volatile(
47 "fstcw %[saved]\n\t"
48 "fwait\n\t"
49 "movw %[saved], %%ax\n\t"
50 "orw $0x0c00, %%ax\n\t"
51 "movw %%ax, %[truncating]\n\t"
52 "fldcw %[truncating]\n\t"
53 "fistpq %[result]\n\t"
54 "fldcw %[saved]"
55 : [result] "=m"(result), [saved] "=m"(saved_control),
56 [truncating] "=m"(truncating_control)
57 : "t"(value)
58 : "eax", "st", "cc");
59 return result;
60}
61
62// Original pcdogs.exe: 0x446f40
63// Sets the CRT's default floating-point precision through the abstract control-word interface.
68
69// Original pcdogs.exe: 0x446f52
70// Runs the fixed arithmetic check used when the processor-feature query is unavailable and reports whether its residual exceeds the expected tolerance.
72{
73 static const double divisor = 3145727.0;
74 static const double dividend = 4195835.0;
75 static const double threshold = 1.0;
76 double test_divisor, test_dividend, residual;
77 uint16_t comparison_status;
78
79 /* Preserve the hardware probe and its x87 condition/exception flags. */
80 __asm__ volatile(
81 "fldl %[divisor]\n\t"
82 "fstpl %[test_divisor]\n\t"
83 "fldl %[dividend]\n\t"
84 "fstpl %[test_dividend]\n\t"
85 "fldl %[test_dividend]\n\t"
86 "fdivl %[test_divisor]\n\t"
87 "fmull %[test_divisor]\n\t"
88 "fsubrl %[test_dividend]\n\t"
89 "fstpl %[residual]\n\t"
90 "fldl %[residual]\n\t"
91 "fcompl %[threshold]\n\t"
92 "fnstsw %%ax"
93 : "=a"(comparison_status), [test_divisor] "=m"(test_divisor),
94 [test_dividend] "=m"(test_dividend), [residual] "=m"(residual)
95 : [divisor] "m"(divisor), [dividend] "m"(dividend),
96 [threshold] "m"(threshold)
97 : "st");
98 return !(comparison_status & (X87_STATUS_C3 | X87_STATUS_C0));
99}
100
101// Original pcdogs.exe: 0x446f90
102// Queries Windows for the Pentium floating-point division erratum when that API is available. Otherwise it runs the arithmetic fallback check.
104{
105 HMODULE h_module = g_crtGetModuleHandleAPtr("KERNEL32");
106
107 if (!h_module)
108 /* tailcall */
110
111 BOOL(WINAPI * is_processor_feature_present)(DWORD) = (void *)GetProcAddress(h_module, "IsProcessorFeaturePresent");
112
113 if (is_processor_feature_present)
114 return is_processor_feature_present(0);
115
116 /* tailcall */
118}
119
120// Original pcdogs.exe: 0x446fb9
121// Inserts the locale decimal-point character after the initial digit run, shifting the suffix including its terminator. The caller must supply a representation that needs the insertion.
122void _forcdecpt(char *buffer)
123{
124 char *decimal_position = buffer;
125
126 if (CRT_tolower((int32_t)*(uint8_t *)decimal_position) != 'e')
127 {
128 int32_t is_digit;
129
130 do
131 {
132 decimal_position = &decimal_position[1];
133
134 if (g_crtLcCodepage <= 1)
135 {
136 uint32_t digit_class_bits = (int32_t)*(uint8_t *)decimal_position;
137
138 is_digit = ((struct CRT_CharacterClass *)g_pCharTypeTable)[digit_class_bits].classification_flags & CRT_CTYPE_DIGIT;
139 }
140 else
141 is_digit = CRT_isctype((int32_t)*(uint8_t *)decimal_position, CRT_CTYPE_DIGIT);
142 } while (is_digit);
143 }
144
145 char displaced_character = *(uint8_t *)decimal_position;
146
147 *(uint8_t *)decimal_position = g_decimalPointChar;
148
149 char *shift_cursor = &decimal_position[1];
150 char shifted_character;
151
152 do
153 {
154 shifted_character = *(uint8_t *)shift_cursor;
155 *(uint8_t *)shift_cursor = displaced_character;
156 displaced_character = shifted_character;
157 shifted_character = *(uint8_t *)shift_cursor;
158 shift_cursor = &shift_cursor[1];
159 } while (shifted_character);
160}
161
162// Original pcdogs.exe: 0x447013
163// Removes trailing fractional zeroes and an unneeded decimal point from a formatted number while preserving any exponent suffix.
164void _cropzeros(char *formatted_string)
165{
166 char *decimal_cursor = formatted_string;
167 char decimal_or_suffix_character = g_decimalPointChar;
168 char character = *(uint8_t *)decimal_cursor;
169
170 if (character)
171 {
172 while (character != decimal_or_suffix_character)
173 {
174 character = decimal_cursor[1];
175 decimal_cursor = &decimal_cursor[1];
176
177 if (!character)
178 break;
179 }
180 }
181
182 char *trim_cursor = &decimal_cursor[1];
183
184 if (!*(uint8_t *)decimal_cursor)
185 return;
186
187 while (true)
188 {
189 character = *(uint8_t *)trim_cursor;
190
191 if (!character)
192 break;
193
194 if (character == 'e')
195 break;
196
197 if (character == 'E')
198 break;
199
200 trim_cursor = &trim_cursor[1];
201 }
202
203 char *exponent_cursor = trim_cursor;
204
205 do
206 trim_cursor -= 1;
207
208 while (*(uint8_t *)trim_cursor == '0');
209
210 if (*(uint8_t *)trim_cursor == (uint8_t)decimal_or_suffix_character)
211 trim_cursor -= 1;
212
213 do
214 {
215 decimal_or_suffix_character = *(uint8_t *)exponent_cursor;
216 trim_cursor = &trim_cursor[1];
217 exponent_cursor = &exponent_cursor[1];
218 *(uint8_t *)trim_cursor = decimal_or_suffix_character;
219 } while (decimal_or_suffix_character);
220}
221
222// Original pcdogs.exe: 0x447061
223// Reports whether a floating-point value is nonnegative and not a NaN.
224int32_t _positive(double const *value)
225{
226 return !isnan(*value) && *value >= 0.0;
227}
228
229// Original pcdogs.exe: 0x447079
230// Parses text and stores either a float or a double according to the requested assignment format.
231void __fassign(int32_t flag, void *destination, char const *number)
232{
233 if (flag)
234 __atodbl((double *)destination, number);
235 else
236 __atoflt((float *)destination, number);
237}
238
239// Original pcdogs.exe: 0x4470b7
240// Formats a floating-point value in scientific notation with the requested fractional precision and exponent letter case. It returns the destination buffer.
241char *_cftoe(double const *value, char *buffer, int32_t precision, int32_t uppercase_exponent)
242{
243 int32_t effective_precision;
244 int32_t *conversion_record;
245
247 {
248 __fpmath(*value);
249 effective_precision = precision;
250 conversion_record = &g_crtFloatState;
251
252 int32_t sign_bytes = g_crtFloatState == '-';
253 uintptr_t decimal_point_bytes = effective_precision > 0;
254
255 String_RoundAndCopyDigitsFloat((uintptr_t)decimal_point_bytes + &buffer[sign_bytes], effective_precision + 1,
257 }
258 else
259 {
260 effective_precision = precision;
261
262 int32_t *existing_conversion_record = (int32_t *)(g_floatFormatPrecision);
263 int32_t insert_count = effective_precision > 0;
264
265 conversion_record = existing_conversion_record;
266
267 int32_t existing_sign_bytes = *(uint32_t *)existing_conversion_record == '-';
268
269 String_MakeInsertionGap((uintptr_t)existing_sign_bytes + buffer, insert_count);
270 }
271
272 char *mantissa_cursor = buffer;
273
274 if (*(uint32_t *)conversion_record == '-')
275 {
276 *(uint8_t *)mantissa_cursor = '-';
277 mantissa_cursor = &mantissa_cursor[1];
278 }
279
280 if (effective_precision > 0)
281 {
282 *(uint8_t *)mantissa_cursor = mantissa_cursor[1];
283 mantissa_cursor = &mantissa_cursor[1];
284 *(uint8_t *)mantissa_cursor = g_decimalPointChar;
285 }
286
287 uintptr_t leading_digit_bytes = !g_floatFormatFlags;
288 char *exponent_text = CRT_strcpy((uintptr_t)leading_digit_bytes + mantissa_cursor + effective_precision, "e+000");
289
290 if (uppercase_exponent)
291 *(uint8_t *)exponent_text = 'E';
292
293 if (*(uint8_t *)conversion_record[3] == '0')
294 return buffer;
295
296 int32_t decimal_point_position = conversion_record[1];
297 int32_t exponent_magnitude = decimal_point_position - 1;
298
299 if (decimal_point_position - 1 < 0)
300 {
301 exponent_magnitude = -(exponent_magnitude);
302 exponent_text[1] = '-';
303 }
304
305 if (exponent_magnitude >= 0x64)
306 {
307 exponent_text[2] += (char)((int64_t)exponent_magnitude / 0x64);
308 exponent_magnitude = (int64_t)exponent_magnitude % 0x64;
309 }
310
311 if (exponent_magnitude >= 0xa)
312 {
313 exponent_text[3] += (char)((int64_t)exponent_magnitude / 0xa);
314 exponent_magnitude = (int64_t)exponent_magnitude % 0xa;
315 }
316
317 exponent_text[4] += (uint8_t)exponent_magnitude;
318
319 return buffer;
320}
321
322// Original pcdogs.exe: 0x4471bb
323// Formats a floating-point value in fixed notation with the requested fractional precision and returns the destination buffer.
324char *_cftof(double const *value, char *buffer, int32_t precision)
325{
326 int32_t effective_precision;
327 int32_t *conversion_record;
328
330 {
331 __fpmath(*value);
332 effective_precision = precision;
333 conversion_record = &g_crtFloatState;
334
335 int32_t sign_bytes = g_crtFloatState == '-';
336
337 String_RoundAndCopyDigitsFloat((uintptr_t)sign_bytes + buffer, g_crtFloatPrecision + effective_precision,
339 }
340 else
341 {
342 int32_t stored_precision = g_crtHeapInitialized;
343
344 effective_precision = precision;
345 conversion_record = (int32_t *)(g_floatFormatPrecision);
346
347 if (stored_precision == effective_precision)
348 {
349 int32_t existing_sign_bytes = *(uint32_t *)conversion_record == '-';
350 char *trailing_zero_slot = (uintptr_t)existing_sign_bytes + stored_precision + buffer;
351
352 *(uint8_t *)trailing_zero_slot = '0';
353 trailing_zero_slot[1] = 0;
354 }
355 }
356
357 char *mantissa_start = buffer;
358
359 if (*(uint32_t *)conversion_record == '-')
360 {
361 *(uint8_t *)buffer = '-';
362 mantissa_start = &buffer[1];
363 }
364
365 int32_t decimal_point_position = conversion_record[1];
366 char *decimal_point_slot;
367
368 if (decimal_point_position > 0)
369 decimal_point_slot = &mantissa_start[decimal_point_position];
370 else
371 {
372 String_MakeInsertionGap(mantissa_start, 1);
373 *(uint8_t *)mantissa_start = '0';
374 decimal_point_slot = &mantissa_start[1];
375 }
376
377 if (effective_precision <= 0)
378 return buffer;
379
380 String_MakeInsertionGap(decimal_point_slot, 1);
381 *(uint8_t *)decimal_point_slot = g_decimalPointChar;
382
383 int32_t negative_point_position = conversion_record[1];
384
385 if (negative_point_position < 0)
386 {
388 {
389 int32_t leading_fraction_zeros = -(negative_point_position);
390
391 if (effective_precision >= leading_fraction_zeros)
392 effective_precision = leading_fraction_zeros;
393 }
394 else
395 effective_precision = -(negative_point_position);
396
397 String_MakeInsertionGap(&decimal_point_slot[1], effective_precision);
398 _memset(&decimal_point_slot[1], '0', effective_precision);
399 }
400
401 return buffer;
402}
403
404// Original pcdogs.exe: 0x447299
405// Chooses fixed or scientific notation according to the requested significant-digit precision and returns the destination buffer.
406char *_cftog(double const *value, char *buffer, int32_t precision, int32_t uppercase_exponent)
407{
408 __fpmath(*value);
411
412 int32_t sign_bytes = g_crtFloatState == '-';
413 char *output = (uintptr_t)sign_bytes + buffer;
414
416
417 struct CRT_FloatConversionRecord *conversion_record = (void *)(g_floatFormatPrecision);
418 bool rounding_expanded_exponent = g_crtHeapInitialized < conversion_record->decimalPointPosition - 1;
419
420 g_crtDecimalPoint = rounding_expanded_exponent;
421
422 int32_t decimal_exponent = (uint32_t)conversion_record->decimalPointPosition - 1;
423
424 g_crtHeapInitialized = decimal_exponent;
425
426 if (decimal_exponent < -4 || decimal_exponent >= precision)
427 return String_FormatScientificFloat(value, buffer, precision, uppercase_exponent);
428
429 if (rounding_expanded_exponent)
430 {
431 char trailing_character;
432
433 do
434 {
435 trailing_character = *(uint8_t *)output;
436 output = &output[1];
437 } while (trailing_character);
438
439 output[-2] &= trailing_character;
440 }
441
442 return String_FormatFixedUsingCachedDigits(value, buffer, precision);
443}
444
445// Original pcdogs.exe: 0x447334
446// Formats scientific notation using the cached digit state, enabling that mode for the call and clearing it afterward.
447char *String_FormatScientificFloat(double const *value, char *buffer, int32_t precision, int32_t uppercase_exponent)
448{
450
451 char *result = _cftoe(value, buffer, precision, uppercase_exponent);
452
454
455 return result;
456}
457
458// Original pcdogs.exe: 0x44735b
459// Formats fixed notation using the cached digit state, enabling that mode for the call and clearing it afterward.
460char *String_FormatFixedUsingCachedDigits(double const *value, char *buffer, int32_t precision)
461{
463
464 char *result = _cftof(value, buffer, precision);
465
467
468 return result;
469}
470
471// Original pcdogs.exe: 0x44737e
472// Dispatches floating-point formatting to scientific, fixed, or general notation according to the conversion character.
473char *__cfltcvt(double const *value, char *buffer, int32_t format, int32_t precision, int32_t uppercase_exponent)
474{
475 if (format == 'e' || format == 'E')
476 return _cftoe(value, buffer, precision, uppercase_exponent);
477
478 if (format != 'f')
479 return _cftog(value, buffer, precision, uppercase_exponent);
480
481 return _cftof(value, buffer, precision);
482}
483
484// Original pcdogs.exe: 0x44a2dc
485// Reads the x87 control word, applies the requested abstract mask, writes the translated result, and returns the resulting abstract control flags.
486uint32_t CRT_control87(uint32_t new_control, uint32_t mask)
487{
488 uint16_t cw;
489
490 __asm__ volatile("fstcw %0" : "=m"(cw));
491
492 uint32_t result = (_cw_to_abstract_cw(cw) & ~mask) | (new_control & mask);
493
494 cw = (uint16_t)_abstract_cw_to_cw(result);
495 __asm__ volatile("fldcw %0" : : "m"(cw));
496
497 return result;
498}
499
500// Original pcdogs.exe: 0x44a311
501// Updates floating-point control flags while excluding the denormal-exception mask from the requested changes.
502uint32_t CRT_controlfp(uint32_t new_value, uint32_t mask)
503{
504 return CRT_control87(new_value, mask & ~CRT_CONTROL_DENORMAL_MASK);
505}
506
507// Original pcdogs.exe: 0x44a327
508// Translates x87 exception, rounding, precision, and infinity-control bits into the CRT's abstract control flags.
509uint32_t _cw_to_abstract_cw(uint32_t control_word)
510{
511 uint32_t exception_masks = ((control_word & X87_CONTROL_INVALID_MASK) << 4) | ((control_word & X87_CONTROL_ZERO_DIVIDE_MASK) << 1) | ((control_word & X87_CONTROL_OVERFLOW_MASK) >> 1) | ((control_word & X87_CONTROL_UNDERFLOW_MASK) >> 3) | ((control_word & X87_CONTROL_INEXACT_MASK) >> 5) | ((control_word & X87_CONTROL_DENORMAL_MASK) << 18);
512 uint32_t rounding_mode = (control_word & X87_CONTROL_ROUNDING_MASK) >> 2;
513 uint32_t hardware_precision = control_word & X87_CONTROL_PRECISION_MASK;
514 uint32_t precision_mode = hardware_precision == X87_PRECISION_SINGLE ? CRT_PRECISION_SINGLE
515 : hardware_precision == X87_PRECISION_DOUBLE ? CRT_PRECISION_DOUBLE
516 : 0;
517 uint32_t infinity_mode = (control_word & X87_CONTROL_INFINITY_AFFINE) << 6;
518
519 return exception_masks | rounding_mode | precision_mode | infinity_mode;
520}
521
522// Original pcdogs.exe: 0x44a3b9
523// Translates the CRT's abstract floating-point control flags into an x87 control word.
524uint32_t _abstract_cw_to_cw(uint32_t abstract_control_word)
525{
526 uint32_t exception_masks = ((abstract_control_word & CRT_CONTROL_INVALID_MASK) >> 4) | ((abstract_control_word & CRT_CONTROL_ZERO_DIVIDE_MASK) >> 1) | ((abstract_control_word & CRT_CONTROL_OVERFLOW_MASK) << 1) | ((abstract_control_word & CRT_CONTROL_UNDERFLOW_MASK) << 3) | ((abstract_control_word & CRT_CONTROL_INEXACT_MASK) << 5) | ((abstract_control_word & CRT_CONTROL_DENORMAL_MASK) >> 18);
527 uint32_t rounding_mode = (abstract_control_word & CRT_CONTROL_ROUNDING_MASK) << 2;
528 uint32_t abstract_precision = abstract_control_word & CRT_CONTROL_PRECISION_MASK;
529 uint32_t precision_mode = abstract_precision == CRT_PRECISION_EXTENDED ? X87_PRECISION_EXTENDED
530 : abstract_precision == CRT_PRECISION_DOUBLE ? X87_PRECISION_DOUBLE
531 : 0;
532 uint32_t infinity_mode = (abstract_control_word & CRT_CONTROL_INFINITY_AFFINE) >> 6;
533
534 return exception_masks | rounding_mode | precision_mode | infinity_mode;
535}
536
537// Original pcdogs.exe: 0x44a50d
538// Tests whether all bits strictly after the selected bit are clear in a most-significant-word-first 96-bit mantissa. Bit zero denotes the top bit of the first word.
539int32_t __ld12_is_zero_upper(uint32_t const *value, int32_t start_bit)
540{
541 int32_t start_word_index = (int64_t)start_bit / CRT_WORD_BITS;
542
543 if (value[start_word_index] & ~(UINT32_MAX << ((CRT_WORD_SHIFT_MASK - (char)((int64_t)start_bit % CRT_WORD_BITS)) & CRT_WORD_SHIFT_MASK)))
544 return 0;
545
546 int32_t word_index = start_word_index + 1;
547
548 if (word_index >= 3)
549 return 1;
550
551 const uint32_t *word_cursor = &value[word_index];
552
553 while (true)
554 {
555 if (*(uint32_t *)word_cursor)
556 return 0;
557
558 word_index += 1;
559 word_cursor = &word_cursor[1];
560
561 if (word_index >= 3)
562 return 1;
563 }
564}
565
566// Original pcdogs.exe: 0x44a556
567// Adds the selected bit to a most-significant-word-first 96-bit mantissa and propagates carries toward earlier words. It returns any carry beyond the first word.
568int32_t __ld12_increment(uint32_t *value, int32_t bit_index)
569{
570 int32_t bit_word_index = (int64_t)bit_index / CRT_WORD_BITS;
571 uint32_t *sum = &value[bit_word_index];
572 int32_t carry = __add_with_overflow_check(*(uint32_t *)sum,
573 1U << ((CRT_WORD_SHIFT_MASK - (char)((int64_t)bit_index % CRT_WORD_BITS)) & CRT_WORD_SHIFT_MASK), sum);
574 int32_t carry_word_index = bit_word_index - 1;
575
576 if (bit_word_index - 1 >= 0)
577 {
578 uint32_t *carry_word = &value[carry_word_index];
579
580 while (carry)
581 {
582 carry = __add_with_overflow_check(*carry_word, 1, carry_word);
583 carry_word_index -= 1;
584 carry_word -= 1;
585
586 if (carry_word_index < 0)
587 break;
588 }
589 }
590
591 return carry;
592}
593
594// Original pcdogs.exe: 0x44a5ac
595// Applies the CRT's legacy mantissa rounding and clearing rule. The rule ignores the bit immediately after the selected bit when testing the remaining tail and retains the selected bit while clearing lower bits.
596int32_t __ld12_round_and_clear(uint32_t *value, int32_t bit_index)
597{
598 int32_t round_bit_index = bit_index - 1;
599 int32_t carry_out = 0;
600 int32_t guard_word_index = (int64_t)(round_bit_index + 1) / CRT_WORD_BITS;
601 uint32_t guard_shift = (CRT_WORD_SHIFT_MASK - (uint32_t)bit_index) & CRT_WORD_SHIFT_MASK;
602 uint32_t *guard_word = &value[guard_word_index];
603
604 if ((*guard_word & (1U << guard_shift)) && !__ld12_is_zero_upper(value, round_bit_index + 2))
605 carry_out = __ld12_increment(value, round_bit_index);
606
607 *guard_word &= UINT32_MAX << guard_shift;
608
609 if (guard_word_index + 1 < 3)
610 __builtin_memset(&value[guard_word_index + 1], 0, (3 - (guard_word_index + 1)) << 2);
611
612 return carry_out;
613}
614
615// Original pcdogs.exe: 0x44a638
616// Copies all three words of a 96-bit mantissa.
617void __ld12_copy(uint32_t *dest, uint32_t const *src)
618{
619 for (unsigned i = 0; i < 3; ++i)
620 dest[i] = src[i];
621}
622
623// Original pcdogs.exe: 0x44a653
624// Clears all three words of a 96-bit mantissa.
625void __ld12_clear(uint32_t *value)
626{
627 value[0] = 0;
628 value[1] = 0;
629 value[2] = 0;
630}
631
632// Original pcdogs.exe: 0x44a65f
633// Reports whether all three words of a 96-bit mantissa are zero.
634int32_t __ld12_is_zero(uint32_t const *value)
635{
636 uint32_t const *word_cursor = value;
637 int32_t words_checked = 0;
638
639 while (!*(uint32_t *)word_cursor)
640 {
641 words_checked += 1;
642 word_cursor = &word_cursor[1];
643
644 if (words_checked >= 3)
645 return 1;
646 }
647
648 return 0;
649}
650
651// Original pcdogs.exe: 0x44a67a
652// Shifts a most-significant-word-first 96-bit mantissa right in place, carrying bits across word boundaries.
653void __ld12_shr(uint32_t *value, int32_t bit_count)
654{
655 unsigned word_shift = (unsigned)bit_count / 32, bit_shift = (unsigned)bit_count % 32;
656
657 uint32_t original_words[3] = {value[0], value[1], value[2]};
658
659 for (int i = 2; i >= 0; --i)
660 {
661 value[i] = (unsigned)i < word_shift ? 0 : original_words[i - word_shift] >> bit_shift;
662
663 if (bit_shift && (unsigned)i > word_shift)
664 value[i] |= original_words[i - word_shift - 1] << (32 - bit_shift);
665 }
666}
667
668// Original pcdogs.exe: 0x44a707
669// Converts the CRT packed extended value into the IEEE layout described by the supplied format descriptor. It preserves the sign and returns zero for normal or zero results, one for overflow, and two for subnormal or underflow results.
670int32_t __ld12_to_ieee(struct CRT_LD12Fields const *value, void *output, struct CRT_IEEEFormatDescriptor const *format)
671{
672 uint32_t sign_exponent = (uint32_t)value->sign_exponent;
673 uint32_t working_mantissa[0x3];
674
675 working_mantissa[0] = value->mantissa_high;
676
677 uint32_t extra_mantissa = (uint32_t)value->extra_mantissa;
678 int32_t unbiased_exponent = (sign_exponent & CRT_EXTENDED_EXPONENT_MASK) - CRT_EXTENDED_EXPONENT_BIAS;
679
680 working_mantissa[1] = value->mantissa_low;
681 working_mantissa[2] = extra_mantissa << 0x10;
682
683 int32_t result;
684 int32_t output_exponent;
685
686 if (unbiased_exponent != -CRT_EXTENDED_EXPONENT_BIAS)
687 {
688 uint32_t original_mantissa[0x3];
689
690 __ld12_copy(original_mantissa, working_mantissa);
691
692 if (__ld12_round_and_clear(working_mantissa, format->precision_bits))
693 unbiased_exponent += 1;
694
695 int32_t subnormal_exponent = format->subnormal_exponent;
696
697 if (unbiased_exponent >= subnormal_exponent - format->precision_bits)
698 {
699 if (unbiased_exponent <= subnormal_exponent)
700 {
701 __ld12_copy(working_mantissa, original_mantissa);
702 __ld12_shr(working_mantissa, subnormal_exponent - unbiased_exponent);
703 __ld12_round_and_clear(working_mantissa, format->precision_bits);
704 __ld12_shr(working_mantissa, format->exponent_bits + 1);
705
706 output_exponent = 0;
707 result = CRT_FLOAT_UNDERFLOW;
708 }
709 else if (unbiased_exponent < format->overflow_exponent)
710 {
711 int32_t normal_exponent_bits = format->exponent_bits;
712 int32_t exponent_bias = format->exponent_bias;
713
714 working_mantissa[0] &= ~CRT_EXTENDED_MANTISSA_INTEGER_BIT;
715 output_exponent = exponent_bias + unbiased_exponent;
716 __ld12_shr(working_mantissa, normal_exponent_bits);
717 result = CRT_FLOAT_NORMAL;
718 }
719 else
720 {
721 __ld12_clear(working_mantissa);
722
723 int32_t exponent_bits = format->exponent_bits;
724
725 working_mantissa[0] |= CRT_EXTENDED_MANTISSA_INTEGER_BIT;
726 __ld12_shr(working_mantissa, exponent_bits);
727 output_exponent = format->exponent_bias + format->overflow_exponent;
728 result = CRT_FLOAT_OVERFLOW;
729 }
730 }
731 else
732 {
733 __ld12_clear(working_mantissa);
734
735 output_exponent = 0;
736 result = CRT_FLOAT_UNDERFLOW;
737 }
738 }
739 else
740 {
741 output_exponent = 0;
742
743 if (__ld12_is_zero(working_mantissa))
744 result = CRT_FLOAT_NORMAL;
745 else
746 {
747 __ld12_clear(working_mantissa);
748 result = CRT_FLOAT_UNDERFLOW;
749 }
750 }
751
752 int32_t storage_bits = format->storage_bits;
753 int32_t output_high_word = output_exponent << ((CRT_WORD_SHIFT_MASK - (char)format->exponent_bits) & CRT_WORD_SHIFT_MASK) | ((sign_exponent & CRT_EXTENDED_SIGN_MASK) ? CRT_FLOAT_SIGN_MASK : 0U) | working_mantissa[0];
754
755 if (storage_bits == 0x40)
756 {
757 uint32_t *output_words = output;
758 uint32_t output_low_word = working_mantissa[1];
759
760 output_words[1] = output_high_word;
761 *(uint32_t *)output_words = output_low_word;
762 }
763 else if (storage_bits == 0x20)
764 *(uint32_t *)output = output_high_word;
765
766 return result;
767}
768
769// Original pcdogs.exe: 0x44a873
770// Converts the CRT packed extended value to double precision using the double-format descriptor and returns the conversion status.
771int32_t __ld12_to_double(struct CRT_LD12Fields const *value, double *output)
772{
773 return __ld12_to_ieee(value, output, &g_ieeeDoubleFormatDescriptor);
774}
775
776// Original pcdogs.exe: 0x44a889
777// Converts the CRT packed extended value to single precision using the float-format descriptor and returns the conversion status.
778int32_t __ld12_to_float(struct CRT_LD12Fields const *value, float *output)
779{
780 return __ld12_to_ieee(value, output, &g_ieeeFloatFormatDescriptor);
781}
782
783// Original pcdogs.exe: 0x44a89f
784// Parses decimal text into the CRT extended representation, converts it to double precision, and returns the binary-conversion status.
785int32_t __atodbl(double *output, char const *text)
786{
787 struct CRT_LD12Fields parsed_value;
788
789 __strgtold12(&parsed_value, &text, text, 0, 0, 0, 0);
790
791 return __ld12_to_double(&parsed_value, output);
792}
793
794// Original pcdogs.exe: 0x44a8cc
795// Parses decimal text into the CRT extended representation, converts it to single precision, and returns the binary-conversion status.
796int32_t __atoflt(float *output, char const *text)
797{
798 struct CRT_LD12Fields parsed_value;
799
800 __strgtold12(&parsed_value, &text, text, 0, 0, 0, 0);
801
802 return __ld12_to_float(&parsed_value, output);
803}
804
805// Original pcdogs.exe: 0x44a9f0
806// Copies and rounds a requested number of decimal digits into the destination. A carry past the leading digit advances the stored decimal-point position.
807char *String_RoundAndCopyDigitsFloat(char *output, int32_t digit_count, struct CRT_FloatConversionRecord *conversion_state)
808{
809 char *start = output, *digits = conversion_state->mantissaDigits;
810
811 *output++ = '0';
812
813 for (int i = 0; i < digit_count; ++i)
814 *output++ = *digits ? *digits++ : '0';
815
816 *output = 0;
817
818 if (digit_count >= 0 && *digits >= '5')
819 {
820 do
821 {
822 --output;
823
824 if (*output != '9')
825 break;
826
827 *output = '0';
828 } while (1);
829
830 ++*output;
831 }
832
833 if (*start != '1')
834 return CRT_MoveBytesOverlapSafeDuplicate(start, start + 1, _strlen(start + 1) + 1);
835
836 ++conversion_state->decimalPointPosition;
837
838 return output;
839}
840
841// Original pcdogs.exe: 0x44aa67
842// Converts a double into the shared CRT decimal-formatting record, including its sign, decimal-point position, finite-value flag, and digit buffer.
844{
845 struct CRT_Extended80Argument extended_value = {0};
846
847 __double_to_long_double80((uint16_t *)&extended_value, &value);
849 g_crtFloatState = g_crtFloatOutExp.signCharacter;
850 g_crtFloatPrecision = g_crtFloatOutExp.decimalPointPosition;
852
854}
855
856// Original pcdogs.exe: 0x44aacb
857// Converts a double into the CRT's 80-bit extended representation and normalizes subnormal inputs. The original zero path converts negative zero to positive zero.
858void __double_to_long_double80(uint16_t *destination, double const *source)
859{
860 uint64_t bits;
861
862 __builtin_memcpy(&bits, source, 8);
863
864 uint32_t high_word = (uint32_t)(bits >> 32);
865
866 unsigned double_exponent = (high_word >> 20) & CRT_DOUBLE_EXPONENT_MASK;
867
868 uint16_t sign = (high_word >> 16) & CRT_EXTENDED_SIGN_MASK;
869 uint64_t mantissa = ((bits & CRT_DOUBLE_MANTISSA_MASK) << 11);
870 int extended_exponent;
871
872 if (double_exponent)
873 {
874 extended_exponent = double_exponent == CRT_DOUBLE_EXPONENT_MASK ? CRT_EXTENDED_EXPONENT_MASK : (int)double_exponent + (CRT_EXTENDED_EXPONENT_BIAS - CRT_DOUBLE_EXPONENT_BIAS);
875 mantissa |= CRT_EXTENDED_INTEGER_BIT;
876 }
877 else if (!mantissa)
878 {
879 __builtin_memset(destination, 0, 10);
880
881 return;
882 }
883 else
884 {
885 extended_exponent = (CRT_EXTENDED_EXPONENT_BIAS - CRT_DOUBLE_EXPONENT_BIAS + 1);
886
887 while (!(mantissa >> 63))
888 {
889 mantissa <<= 1;
890 --extended_exponent;
891 }
892 }
893
894 __builtin_memcpy(destination, &mantissa, 8);
895 destination[4] = sign | (uint16_t)extended_exponent;
896}
897
898// Original pcdogs.exe: 0x44afab
899// Reports that floating-point support was not loaded and terminates through the CRT fatal-error path.
905
906// Original pcdogs.exe: 0x44bf9d
907// Stores the wrapped sum of two unsigned 32-bit values and returns whether the addition carried.
908int32_t __add_with_overflow_check(uint32_t left, uint32_t right, uint32_t *sum)
909{
910 uint32_t wrapped_sum = left + right;
911
912 *sum = wrapped_sum;
913
914 return wrapped_sum < left;
915}
916
917// Original pcdogs.exe: 0x44bfbe
918// Adds a little-endian three-word integer into another, propagating carries across the 96-bit result.
919void ___add_12(uint32_t *accumulator, uint32_t const *addend)
920{
921 if (__add_with_overflow_check(accumulator[0], *(uint32_t *)addend, accumulator) && __add_with_overflow_check(accumulator[1], 1, &accumulator[1]))
922 accumulator[2] += 1;
923
924 if (__add_with_overflow_check(accumulator[1], addend[1], &accumulator[1]))
925 accumulator[2] += 1;
926
927 __add_with_overflow_check(accumulator[2], addend[2], &accumulator[2]);
928}
929
930// Original pcdogs.exe: 0x44c01c
931// Shifts a little-endian 96-bit integer left by one bit, carrying between its three words.
932void __shl_12byte(uint32_t *value)
933{
934 uint32_t lo = value[0], mid = value[1], hi = value[2];
935
936 value[0] = lo << 1;
937 value[1] = (mid << 1) | (lo >> 31);
938 value[2] = (hi << 1) | (mid >> 31);
939}
940
941// Original pcdogs.exe: 0x44c04a
942// Shifts a little-endian 96-bit integer right by one bit, carrying between its three words.
943void __shr_12byte(uint32_t *value)
944{
945 uint32_t high_word = value[2];
946 uint32_t middle_word = value[1];
947
948 value[1] = middle_word >> 1 | high_word << CRT_WORD_SHIFT_MASK;
949
950 uint32_t shifted_low_word = *(uint32_t *)value >> 1 | middle_word << CRT_WORD_SHIFT_MASK;
951
952 value[2] = high_word >> 1;
953 *(uint32_t *)value = shifted_low_word;
954}
955
956// Original pcdogs.exe: 0x44c077
957// Accumulates numeric decimal digits into a 96-bit integer and normalizes the resulting extended mantissa. The digits are values from zero through nine rather than ASCII, and the normalization path requires a nonzero mantissa.
958void __mtold12(uint8_t const *digits, uint32_t digit_count, struct CRT_LD12Fields *output)
959{
960 uint32_t mantissa_words[3] = {0, 0, 0};
961 uint16_t exponent = (CRT_EXTENDED_EXPONENT_BIAS + 79);
962
963 for (uint32_t i = 0; i < digit_count; ++i)
964 {
965 uint64_t carry = digits[i];
966
967 for (int j = 0; j < 3; ++j)
968 {
969 carry += (uint64_t)mantissa_words[j] * 10;
970 mantissa_words[j] = (uint32_t)carry;
971 carry >>= 32;
972 }
973 }
974
975 while (!(mantissa_words[2] & UINT16_MAX))
976 {
977 mantissa_words[2] = (mantissa_words[2] << 16) | (mantissa_words[1] >> 16);
978 mantissa_words[1] = (mantissa_words[1] << 16) | (mantissa_words[0] >> 16);
979 mantissa_words[0] <<= 16;
980 exponent -= 16;
981 }
982
983 while (!(mantissa_words[2] & CRT_EXTENDED_SIGN_MASK))
984 {
985 __shl_12byte(mantissa_words);
986 --exponent;
987 }
988
989 memcpy(output, mantissa_words, 12);
990 output->sign_exponent = exponent;
991}
992
993// Original pcdogs.exe: 0x44c9e8
994// Multiplies packed extended values using the CRT's truncated limb products and legacy normalization and rounding rules. Exponent-all-ones operands follow the signed-infinity path, while the early zero path produces positive zero.
995void __flt_mul(struct CRT_LD12Fields *left_and_result, struct CRT_LD12Fields const *right)
996{
997 uint16_t right_sign_exponent = right->sign_exponent;
998 uint16_t left_sign_exponent = left_and_result->sign_exponent;
999 int32_t discarded_one_count = 0;
1000 uint32_t product_words[0x3];
1001
1002 product_words[0] = 0;
1003 product_words[1] = 0;
1004 product_words[2] = 0;
1005
1006 int32_t left_exponent = left_sign_exponent & CRT_EXTENDED_EXPONENT_MASK;
1007 uint32_t right_exponent = right_sign_exponent & CRT_EXTENDED_EXPONENT_MASK;
1008 uint32_t result_sign = (right_sign_exponent ^ left_sign_exponent) & CRT_EXTENDED_SIGN_MASK;
1009 uint32_t exponent_sum = right_exponent + left_exponent;
1010 int32_t result_exponent = exponent_sum;
1011
1012 if ((uint16_t)left_exponent >= CRT_EXTENDED_EXPONENT_MASK || (uint16_t)right_exponent >= CRT_EXTENDED_EXPONENT_MASK || (uint16_t)exponent_sum > CRT_EXTENDED_PRODUCT_OVERFLOW_SUM)
1013 {
1014 left_and_result->mantissa_low_upper_word = 0;
1015 left_and_result->mantissa_high = 0;
1016 left_and_result->extra_mantissa = 0;
1017 left_and_result->mantissa_low = 0;
1018 left_and_result->mantissa_high_upper_word =
1019 (((uint16_t)result_sign) ? 4294934528U : 2147450880U);
1020 left_and_result->sign_exponent = (uint16_t)(CRT_EXTENDED_EXPONENT_MASK | result_sign);
1021
1022 return;
1023 }
1024
1025 if ((uint16_t)exponent_sum <= CRT_EXTENDED_PRODUCT_UNDERFLOW_SUM)
1026 {
1027 left_and_result->mantissa_high_upper_word = 0;
1028 left_and_result->sign_exponent = 0;
1029 left_and_result->mantissa_low_upper_word = 0;
1030 left_and_result->mantissa_high = 0;
1031 left_and_result->extra_mantissa = 0;
1032 left_and_result->mantissa_low = 0;
1033
1034 return;
1035 }
1036
1037 if (!(uint16_t)left_exponent)
1038 {
1039 result_exponent += 1;
1040
1041 if (!(left_and_result->encoding_words[2] & INT32_MAX) && !(left_and_result->encoding_words[1] || left_and_result->encoding_words[0]))
1042 {
1043 left_and_result->sign_exponent = 0;
1044
1045 return;
1046 }
1047 }
1048
1049 if (!(uint16_t)right_exponent)
1050 result_exponent += 1;
1051
1052 if (!(uint16_t)right_exponent && !(right->encoding_words[2] & INT32_MAX) && !right->encoding_words[1] && !right->encoding_words[0])
1053 {
1054 left_and_result->mantissa_high_upper_word = 0;
1055 left_and_result->sign_exponent = 0;
1056 left_and_result->mantissa_low_upper_word = 0;
1057 left_and_result->mantissa_high = 0;
1058 left_and_result->extra_mantissa = 0;
1059 left_and_result->mantissa_low = 0;
1060
1061 return;
1062 }
1063
1064 int32_t diagonal_index = 0;
1065 uint16_t *carry_word_cursor = (uint16_t *)(&product_words[1]);
1066
1067 for (int32_t diagonal_product_count = 5; diagonal_product_count > 0; diagonal_product_count -= 1)
1068 {
1069 if (diagonal_product_count > 0)
1070 {
1071 uint16_t const *left_limb_cursor = (const uint16_t *)(diagonal_index * 2 + (int32_t)left_and_result);
1072 uint16_t const *right_limb_cursor = (const uint16_t *)((int32_t)&right->mantissa_high + 2);
1073 int32_t inner_product_count = diagonal_product_count;
1074
1075 do
1076 {
1077 if (__add_with_overflow_check(*(uint32_t *)((int32_t)carry_word_cursor - 4),
1078 (uint32_t)*(uint16_t *)left_limb_cursor * (uint32_t)*(uint16_t *)right_limb_cursor,
1079 (uint32_t *)(&carry_word_cursor[-2])))
1080 *(uint16_t *)carry_word_cursor += 1;
1081
1082 left_limb_cursor = &left_limb_cursor[1];
1083 right_limb_cursor = (const uint16_t *)((int32_t)right_limb_cursor - 2);
1084 } while (--inner_product_count);
1085 }
1086
1087 carry_word_cursor = &carry_word_cursor[1];
1088 diagonal_index += 1;
1089 }
1090
1091 result_exponent += (uint16_t)(1 - CRT_EXTENDED_EXPONENT_BIAS);
1092
1093 if ((int16_t)result_exponent > 0)
1094 {
1095 while (!(product_words[2] & CRT_EXTENDED_MANTISSA_INTEGER_BIT))
1096 {
1097 __shl_12byte((uint32_t *)(&product_words));
1098 result_exponent += UINT16_MAX;
1099
1100 if ((int16_t)result_exponent <= 0)
1101 break;
1102 }
1103 }
1104
1105 if ((int16_t)result_exponent <= 0)
1106 {
1107 result_exponent += UINT16_MAX;
1108
1109 if ((int16_t)result_exponent < 0)
1110 {
1111 int32_t denormal_shift_count = -((int32_t)(int16_t)result_exponent);
1112
1113 result_exponent += denormal_shift_count;
1114
1115 int32_t shifts_remaining = denormal_shift_count;
1116
1117 do
1118 {
1119 if (product_words[0] & CRT_MANTISSA_STICKY_BIT)
1120 discarded_one_count += 1;
1121
1122 __shr_12byte((uint32_t *)(&product_words));
1123 } while (--shifts_remaining);
1124
1125 if (discarded_one_count)
1126 product_words[0] |= CRT_MANTISSA_STICKY_BIT;
1127 }
1128 }
1129
1130 if ((uint16_t)product_words[0] > CRT_MANTISSA_ROUND_BIT || (product_words[0] & (UINT16_MAX | CRT_MANTISSA_ROUND_EVEN_BIT)) == (CRT_MANTISSA_ROUND_BIT | CRT_MANTISSA_ROUND_EVEN_BIT))
1131 {
1132 if (*(uint32_t *)((char *)&product_words[0] + 2) != 0xffffffff)
1133 *(uint32_t *)((char *)&product_words[0] + 2) += 1;
1134 else
1135 {
1136 *(uint32_t *)((char *)&product_words[0] + 2) = 0;
1137
1138 if (*(uint32_t *)((char *)&product_words[1] + 2) != 0xffffffff)
1139 *(uint32_t *)((char *)&product_words[1] + 2) += 1;
1140 else
1141 {
1142 *(uint32_t *)((char *)&product_words[1] + 2) = 0;
1143
1144 if (*(uint16_t *)((char *)&product_words[2] + 2) != 0xffff)
1145 *(uint16_t *)((char *)&product_words[2] + 2) += 1;
1146 else
1147 {
1148 result_exponent += 1;
1149 *(uint16_t *)((char *)&product_words[2] + 2) = (CRT_EXTENDED_MANTISSA_INTEGER_BIT >> 16);
1150 }
1151 }
1152 }
1153 }
1154
1155 int16_t packed_result_exponent = (uint16_t)result_exponent;
1156
1157 if (packed_result_exponent >= CRT_EXTENDED_EXPONENT_MASK)
1158 {
1159 left_and_result->mantissa_low_upper_word = 0;
1160 left_and_result->mantissa_high = 0;
1161 left_and_result->extra_mantissa = 0;
1162 left_and_result->mantissa_low = 0;
1163 left_and_result->mantissa_high_upper_word =
1164 (((uint16_t)result_sign) ? 4294934528U : 2147450880U);
1165 left_and_result->sign_exponent = (uint16_t)(CRT_EXTENDED_EXPONENT_MASK | result_sign);
1166
1167 return;
1168 }
1169
1170 left_and_result->extra_mantissa = *(uint16_t *)((char *)&product_words[0] + 2);
1171 left_and_result->mantissa_low = product_words[1];
1172 left_and_result->mantissa_high = product_words[2];
1173 left_and_result->sign_exponent = packed_result_exponent | (uint16_t)result_sign;
1174}
1175
1176// Original pcdogs.exe: 0x44cc08
1177// Scales a packed extended value by a signed decimal power using the CRT's positive or reciprocal power tables. A zero power leaves the value untouched, and the legacy signed exponent arithmetic is retained.
1178void __flt_power10(struct CRT_LD12Fields *value, int32_t power, int32_t mult12)
1179{
1180 const struct CRT_LD12Fields *table = g_crtPositivePowersOfTen;
1181 uint32_t power_group_index = 0;
1182
1183 if (!power)
1184 return;
1185
1186 if (power < 0)
1187 {
1188 power = -power;
1190 }
1191
1192 if (!mult12)
1193 value->extra_mantissa = 0;
1194
1195 while (power)
1196 {
1197 unsigned digit = (unsigned)power & (CRT_POWER10_TABLE_RADIX - 1);
1198 power >>= 3;
1199
1200 if (digit)
1201 {
1202 const struct CRT_LD12Fields *right = &table[power_group_index + digit - 1];
1203 struct CRT_LD12Fields adjusted;
1204
1206 {
1207 adjusted = *right;
1208 --adjusted.mantissa_low;
1209 right = &adjusted;
1210 }
1211
1212 __flt_mul(value, right);
1213 }
1214
1215 power_group_index += 7;
1216 }
1217}
1218
1219// Original pcdogs.exe: 0x4473cf
1220// Moves a terminated string right to make an insertion gap at its beginning. The newly opened gap is left uninitialized.
1221void String_MakeInsertionGap(char *buffer, int32_t insert_count)
1222{
1223 if (insert_count)
1224 CRT_MoveBytesOverlapSafeDuplicate(&buffer[insert_count], buffer, _strlen(buffer) + 1);
1225}
void String_MakeInsertionGap(char *buffer, int32_t insert_count)
void __shl_12byte(uint32_t *value)
void _cropzeros(char *formatted_string)
int32_t __ld12_is_zero_upper(uint32_t const *value, int32_t start_bit)
void ___add_12(uint32_t *accumulator, uint32_t const *addend)
char * _cftog(double const *value, char *buffer, int32_t precision, int32_t uppercase_exponent)
char * String_FormatScientificFloat(double const *value, char *buffer, int32_t precision, int32_t uppercase_exponent)
char * _cftoe(double const *value, char *buffer, int32_t precision, int32_t uppercase_exponent)
void __ld12_copy(uint32_t *dest, uint32_t const *src)
int32_t __ld12_is_zero(uint32_t const *value)
int32_t __ld12_round_and_clear(uint32_t *value, int32_t bit_index)
char * String_RoundAndCopyDigitsFloat(char *output, int32_t digit_count, struct CRT_FloatConversionRecord *conversion_state)
char * _cftof(double const *value, char *buffer, int32_t precision)
int32_t __atoflt(float *output, char const *text)
int32_t __ld12_to_ieee(struct CRT_LD12Fields const *value, void *output, struct CRT_IEEEFormatDescriptor const *format)
void __flt_mul(struct CRT_LD12Fields *left_and_result, struct CRT_LD12Fields const *right)
int32_t _positive(double const *value)
int32_t __add_with_overflow_check(uint32_t left, uint32_t right, uint32_t *sum)
uint32_t _cw_to_abstract_cw(uint32_t control_word)
int32_t __ld12_to_double(struct CRT_LD12Fields const *value, double *output)
char * __cfltcvt(double const *value, char *buffer, int32_t format, int32_t precision, int32_t uppercase_exponent)
void __fassign(int32_t flag, void *destination, char const *number)
int32_t __ld12_increment(uint32_t *value, int32_t bit_index)
void __double_to_long_double80(uint16_t *destination, double const *source)
void __ld12_shr(uint32_t *value, int32_t bit_count)
void CRT_AbortFloatSupportNotLoaded()
void __shr_12byte(uint32_t *value)
char * String_FormatFixedUsingCachedDigits(double const *value, char *buffer, int32_t precision)
void _forcdecpt(char *buffer)
struct CRT_FloatConversionRecord * __fpmath(double value)
void CRT_InitializeFloatingPoint()
int32_t CRT_TestFdivBugFallback()
int32_t CRT_TestPentiumFdivBug()
int64_t __ftol_msvc(long double value)
uint32_t _abstract_cw_to_cw(uint32_t abstract_control_word)
void __mtold12(uint8_t const *digits, uint32_t digit_count, struct CRT_LD12Fields *output)
uint32_t CRT_control87(uint32_t new_control, uint32_t mask)
uint32_t CRT_controlfp(uint32_t new_value, uint32_t mask)
void __flt_power10(struct CRT_LD12Fields *value, int32_t power, int32_t mult12)
int32_t __ld12_to_float(struct CRT_LD12Fields const *value, float *output)
void _setdefaultprecision()
void CRT_InitFloatFormatDispatch()
void __ld12_clear(uint32_t *value)
int32_t __atodbl(double *output, char const *text)
#define g_pFloatOutputFunction
#define g_pFloatConvertFunction
#define g_pFloatCropFunction
#define g_crtGetModuleHandleAPtr
#define CRT_MANTISSA_ROUND_BIT
Definition constants.h:168
#define CRT_DOUBLE_EXPONENT_BIAS
Definition constants.h:300
#define X87_CONTROL_PRECISION_MASK
Definition constants.h:127
#define CRT_EXTENDED_INTEGER_BIT
Definition constants.h:161
#define CRT_FLOAT_USE_CACHED_DIGITS
Definition constants.h:308
#define CRT_EXTENDED_MANTISSA_INTEGER_BIT
Definition constants.h:162
#define CRT_MANTISSA_STICKY_BIT
Definition constants.h:167
#define CRT_POWER10_TABLE_RADIX
Definition constants.h:303
#define CRT_DOUBLE_MANTISSA_MASK
Definition constants.h:159
#define CRT_DOUBLE_EXPONENT_MASK
Definition constants.h:158
#define CRT_CONTROL_OVERFLOW_MASK
Definition constants.h:140
#define CRT_FLOAT_SIGN_MASK
Definition constants.h:165
#define X87_STATUS_C0
Definition constants.h:76
#define CRT_CTYPE_DIGIT
Definition constants.h:58
#define CRT_MANTISSA_ROUND_EVEN_BIT
Definition constants.h:169
#define CRT_CONTROL_UNDERFLOW_MASK
Definition constants.h:141
#define X87_CONTROL_INEXACT_MASK
Definition constants.h:125
#define CRT_WORD_BITS
Definition constants.h:287
#define CRT_EXTENDED_EXPONENT_BIAS
Definition constants.h:156
#define X87_CONTROL_UNDERFLOW_MASK
Definition constants.h:124
#define X87_CONTROL_ZERO_DIVIDE_MASK
Definition constants.h:122
@ X87_PRECISION_SINGLE
Definition constants.h:132
@ X87_PRECISION_EXTENDED
Definition constants.h:134
@ X87_PRECISION_DOUBLE
Definition constants.h:133
#define X87_CONTROL_ROUNDING_MASK
Definition constants.h:126
#define CRT_CONTROL_ZERO_DIVIDE_MASK
Definition constants.h:139
@ CRT_FLOAT_UNDERFLOW
Definition constants.h:229
@ CRT_FLOAT_OVERFLOW
Definition constants.h:230
@ CRT_FLOAT_NORMAL
Definition constants.h:228
#define CRT_EXTENDED_EXPONENT_MASK
Definition constants.h:155
#define CRT_CONTROL_INFINITY_AFFINE
Definition constants.h:145
#define CRT_CONTROL_INVALID_MASK
Definition constants.h:137
#define X87_CONTROL_INVALID_MASK
Definition constants.h:120
#define CRT_EXTENDED_PRODUCT_UNDERFLOW_SUM
Definition constants.h:302
#define CRT_EXTENDED_PRODUCT_OVERFLOW_SUM
Definition constants.h:301
#define X87_STATUS_C3
Definition constants.h:78
#define CRT_WORD_SHIFT_MASK
Definition constants.h:288
#define CRT_CONTROL_ROUNDING_MASK
Definition constants.h:143
@ CRT_PRECISION_EXTENDED
Definition constants.h:149
@ CRT_PRECISION_SINGLE
Definition constants.h:151
@ CRT_PRECISION_DOUBLE
Definition constants.h:150
#define CRT_EXTENDED_SIGN_MASK
Definition constants.h:154
#define CRT_CONTROL_PRECISION_MASK
Definition constants.h:144
@ CRT_RUNTIME_FLOAT_UNAVAILABLE
Definition constants.h:256
#define CRT_CONTROL_DENORMAL_MASK
Definition constants.h:138
#define X87_CONTROL_INFINITY_AFFINE
Definition constants.h:128
#define CRT_CONTROL_INEXACT_MASK
Definition constants.h:142
#define X87_CONTROL_OVERFLOW_MASK
Definition constants.h:123
#define X87_CONTROL_DENORMAL_MASK
Definition constants.h:121
void _cropzeros(char *formatted_string)
int32_t __strgtold12(struct CRT_LD12Fields *output, const char **end_pointer, char const *text, int32_t mult12, int32_t scale, int32_t decimal_point, int32_t implicit_exponent)
void __amsg_exit(int32_t runtime_error)
Definition startup.c:205
int32_t CRT_tolower(int32_t ch)
Definition locale.c:241
BOOL String_ConvertToDecimalStringFloat(struct CRT_Extended80Argument value, int32_t digit_count, uint32_t format_flags, struct CRT_DecimalFloatOutput *output)
int32_t _positive(double const *value)
char * __cfltcvt(double const *value, char *buffer, int32_t format, int32_t precision, int32_t uppercase_exponent)
void * CRT_MoveBytesOverlapSafeDuplicate(void *dest, void const *src, uint32_t count)
Definition strings.c:201
void __fassign(int32_t flag, void *destination, char const *number)
void _forcdecpt(char *buffer)
void * _memset(void *dest, int32_t value, uint32_t count)
Definition strings.c:189
uint32_t _strlen(char const *str)
Definition strings.c:225
int32_t CRT_isctype(int32_t ch, int32_t char_type_mask)
Definition locale.c:210
char * CRT_strcpy(char *dest, char const *src)
Definition strings.c:158
#define g_crtFloatPrecision
Definition globals.h:223
#define g_crtDecimalPoint
Definition globals.h:193
#define g_pCRT_FloatHandler2
Definition globals.h:106
#define g_crtFloatingPointMode
Definition globals.h:160
#define g_crtLcCodepage
Definition globals.h:112
#define g_crtFPMathState0
Definition globals.h:226
int32_t global_type_g_crtFPMathState1
Definition globals.h:228
#define g_ieeeDoubleFormatDescriptor
Definition globals.h:145
#define g_crtNegativePowersOfTen
Definition globals.h:334
#define g_crtPositivePowersOfTen
Definition globals.h:333
#define g_pCRT_FloatHandler1
Definition globals.h:103
#define g_crtFPMathState1
Definition globals.h:229
#define g_crtFloatOutExp
Definition globals.h:217
#define g_pCRT_FloatHandler0
Definition globals.h:100
#define g_crtFloatState
Definition globals.h:220
#define g_ieeeFloatFormatDescriptor
Definition globals.h:148
#define g_crtHeapInitialized
Definition globals.h:190
uint8_t classification_flags
Definition types.h:294
int32_t decimalPointPosition
Definition types.h:62
int32_t subnormal_exponent
Definition types.h:112
int32_t overflow_exponent
Definition types.h:111
uint16_t extra_mantissa
Definition types.h:150
uint32_t encoding_words[3]
Definition types.h:177
uint32_t mantissa_low
Definition types.h:154
uint16_t mantissa_high_upper_word
Definition types.h:170
uint16_t mantissa_low_upper_word
Definition types.h:159
uint16_t sign_exponent
Definition types.h:174
uint32_t mantissa_high
Definition types.h:165
int32_t global_type_g_floatFormatPrecision
Definition values.h:527
#define g_floatFormatFlags
Definition values.h:531
#define g_pCharTypeTable
Definition values.h:135
#define g_floatFormatPrecision
Definition values.h:528
#define g_decimalPointChar
Definition values.h:138