1 /* Test of xstrtold() in the "C" locale.
2 Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
27 #include "isnanl-nolibm.h"
28 #include "minus-zero.h"
31 #define UNINIT 0.26149721284764278375542683860869586L
36 /* Subject sequence empty or invalid. */
38 const char input
[] = "";
41 long double result
= UNINIT
;
42 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
44 ASSERT (result
== 0.0L);
45 ASSERT (!signbit (result
));
46 ASSERT (ptr
== input
);
47 ASSERT (errno
== 0 || errno
== EINVAL
);
50 long double result
= UNINIT
;
51 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
53 ASSERT (result
== 0.0L);
54 ASSERT (!signbit (result
));
55 ASSERT (errno
== 0 || errno
== EINVAL
);
59 const char input
[] = " ";
62 long double result
= UNINIT
;
63 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
65 ASSERT (result
== 0.0L);
66 ASSERT (!signbit (result
));
67 ASSERT (ptr
== input
);
68 ASSERT (errno
== 0 || errno
== EINVAL
);
71 long double result
= UNINIT
;
72 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
74 ASSERT (result
== 0.0L);
75 ASSERT (!signbit (result
));
76 ASSERT (errno
== 0 || errno
== EINVAL
);
80 const char input
[] = " +";
83 long double result
= UNINIT
;
84 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
86 ASSERT (result
== 0.0L);
87 ASSERT (!signbit (result
));
88 ASSERT (ptr
== input
);
89 ASSERT (errno
== 0 || errno
== EINVAL
);
92 long double result
= UNINIT
;
93 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
95 ASSERT (result
== 0.0L);
96 ASSERT (!signbit (result
));
97 ASSERT (errno
== 0 || errno
== EINVAL
);
101 const char input
[] = " .";
104 long double result
= UNINIT
;
105 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
107 ASSERT (result
== 0.0L);
108 ASSERT (!signbit (result
));
109 ASSERT (ptr
== input
);
110 ASSERT (errno
== 0 || errno
== EINVAL
);
113 long double result
= UNINIT
;
114 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
116 ASSERT (result
== 0.0L);
117 ASSERT (!signbit (result
));
118 ASSERT (errno
== 0 || errno
== EINVAL
);
122 const char input
[] = " .e0";
125 long double result
= UNINIT
;
126 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
128 ASSERT (result
== 0.0L);
129 ASSERT (!signbit (result
));
130 ASSERT (ptr
== input
);
131 ASSERT (errno
== 0 || errno
== EINVAL
);
134 long double result
= UNINIT
;
135 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
137 ASSERT (result
== 0.0L);
138 ASSERT (!signbit (result
));
139 ASSERT (errno
== 0 || errno
== EINVAL
);
143 const char input
[] = " +.e-0";
146 long double result
= UNINIT
;
147 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
149 ASSERT (result
== 0.0L);
150 ASSERT (!signbit (result
));
151 ASSERT (ptr
== input
);
152 ASSERT (errno
== 0 || errno
== EINVAL
);
155 long double result
= UNINIT
;
156 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
158 ASSERT (result
== 0.0L);
159 ASSERT (!signbit (result
));
160 ASSERT (errno
== 0 || errno
== EINVAL
);
164 const char input
[] = " in";
167 long double result
= UNINIT
;
168 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
170 ASSERT (result
== 0.0L);
171 ASSERT (!signbit (result
));
172 ASSERT (ptr
== input
);
173 ASSERT (errno
== 0 || errno
== EINVAL
);
176 long double result
= UNINIT
;
177 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
179 ASSERT (result
== 0.0L);
180 ASSERT (!signbit (result
));
181 ASSERT (errno
== 0 || errno
== EINVAL
);
185 const char input
[] = " na";
188 long double result
= UNINIT
;
189 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
191 ASSERT (result
== 0.0L);
192 ASSERT (!signbit (result
));
193 ASSERT (ptr
== input
);
194 ASSERT (errno
== 0 || errno
== EINVAL
);
197 long double result
= UNINIT
;
198 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
200 ASSERT (result
== 0.0L);
201 ASSERT (!signbit (result
));
202 ASSERT (errno
== 0 || errno
== EINVAL
);
206 /* Simple floating point values. */
208 const char input
[] = "1";
210 long double result
= UNINIT
;
211 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
213 ASSERT (result
== 1.0L);
214 ASSERT (ptr
== input
+ 1);
218 const char input
[] = "1.";
220 long double result
= UNINIT
;
221 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
223 ASSERT (result
== 1.0L);
224 ASSERT (ptr
== input
+ 2);
228 const char input
[] = ".5";
230 long double result
= UNINIT
;
231 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
233 ASSERT (result
== 0.5L);
234 ASSERT (ptr
== input
+ 2);
238 const char input
[] = " 1";
241 long double result
= UNINIT
;
242 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
244 ASSERT (result
== 1.0L);
245 ASSERT (ptr
== input
+ 2);
249 long double result
= UNINIT
;
250 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
252 ASSERT (result
== 1.0L);
257 const char input
[] = "+1";
259 long double result
= UNINIT
;
260 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
262 ASSERT (result
== 1.0L);
263 ASSERT (ptr
== input
+ 2);
267 const char input
[] = "-1";
269 long double result
= UNINIT
;
270 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
272 ASSERT (result
== -1.0L);
273 ASSERT (ptr
== input
+ 2);
277 const char input
[] = "1e0";
279 long double result
= UNINIT
;
280 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
282 ASSERT (result
== 1.0L);
283 ASSERT (ptr
== input
+ 3);
287 const char input
[] = "1e+0";
289 long double result
= UNINIT
;
290 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
292 ASSERT (result
== 1.0L);
293 ASSERT (ptr
== input
+ 4);
297 const char input
[] = "1e-0";
299 long double result
= UNINIT
;
300 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
302 ASSERT (result
== 1.0L);
303 ASSERT (ptr
== input
+ 4);
307 const char input
[] = "1e1";
309 long double result
= UNINIT
;
310 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
312 ASSERT (result
== 10.0L);
313 ASSERT (ptr
== input
+ 3);
317 const char input
[] = "5e-1";
319 long double result
= UNINIT
;
320 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
322 ASSERT (result
== 0.5L);
323 ASSERT (ptr
== input
+ 4);
329 const char input
[] = "0";
331 long double result
= UNINIT
;
332 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
334 ASSERT (result
== 0.0L);
335 ASSERT (!signbit (result
));
336 ASSERT (ptr
== input
+ 1);
340 const char input
[] = ".0";
342 long double result
= UNINIT
;
343 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
345 ASSERT (result
== 0.0L);
346 ASSERT (!signbit (result
));
347 ASSERT (ptr
== input
+ 2);
351 const char input
[] = "0e0";
353 long double result
= UNINIT
;
354 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
356 ASSERT (result
== 0.0L);
357 ASSERT (!signbit (result
));
358 ASSERT (ptr
== input
+ 3);
362 const char input
[] = "0e+9999999";
364 long double result
= UNINIT
;
365 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
367 ASSERT (result
== 0.0L);
368 ASSERT (!signbit (result
));
369 ASSERT (ptr
== input
+ 10);
373 const char input
[] = "0e-9999999";
375 long double result
= UNINIT
;
376 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
378 ASSERT (result
== 0.0L);
379 ASSERT (!signbit (result
));
380 ASSERT (ptr
== input
+ 10);
384 const char input
[] = "-0";
386 long double result
= UNINIT
;
387 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
389 ASSERT (result
== 0.0L);
390 ASSERT (!!signbit (result
) == !!signbit (minus_zerol
));
391 ASSERT (ptr
== input
+ 2);
397 const char input
[] = "1f";
399 long double result
= UNINIT
;
400 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
402 ASSERT (result
== 1.0L);
403 ASSERT (ptr
== input
+ 1);
407 const char input
[] = "1.f";
409 long double result
= UNINIT
;
410 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
412 ASSERT (result
== 1.0L);
413 ASSERT (ptr
== input
+ 2);
417 const char input
[] = "1e";
420 long double result
= UNINIT
;
421 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
423 ASSERT (result
== 1.0L);
424 ASSERT (ptr
== input
+ 1);
428 long double result
= UNINIT
;
429 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
431 ASSERT (result
== 1.0L);
436 const char input
[] = "1e+";
439 long double result
= UNINIT
;
440 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
442 ASSERT (result
== 1.0L);
443 ASSERT (ptr
== input
+ 1);
447 long double result
= UNINIT
;
448 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
450 ASSERT (result
== 1.0L);
455 const char input
[] = "1e-";
458 long double result
= UNINIT
;
459 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
461 ASSERT (result
== 1.0L);
462 ASSERT (ptr
== input
+ 1);
466 long double result
= UNINIT
;
467 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
469 ASSERT (result
== 1.0L);
474 const char input
[] = "1E 2";
477 long double result
= UNINIT
;
478 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
480 ASSERT (result
== 1.0L);
481 ASSERT (ptr
== input
+ 1);
485 long double result
= UNINIT
;
486 bool ok
= xstrtold (input
, NULL
, &result
, strtold
);
488 ASSERT (result
== 1.0L);
493 const char input
[] = "0x";
495 long double result
= UNINIT
;
496 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
498 ASSERT (result
== 0.0L);
499 ASSERT (!signbit (result
));
500 ASSERT (ptr
== input
+ 1);
504 const char input
[] = "00x1";
506 long double result
= UNINIT
;
507 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
509 ASSERT (result
== 0.0L);
510 ASSERT (!signbit (result
));
511 ASSERT (ptr
== input
+ 2);
515 const char input
[] = "-0x";
517 long double result
= UNINIT
;
518 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
520 ASSERT (result
== 0.0L);
521 ASSERT (!!signbit (result
) == !!signbit (minus_zerol
));
522 ASSERT (ptr
== input
+ 2);
526 const char input
[] = "0xg";
528 long double result
= UNINIT
;
529 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
531 ASSERT (result
== 0.0L);
532 ASSERT (!signbit (result
));
533 ASSERT (ptr
== input
+ 1);
537 const char input
[] = "0xp";
539 long double result
= UNINIT
;
540 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
542 ASSERT (result
== 0.0L);
543 ASSERT (!signbit (result
));
544 ASSERT (ptr
== input
+ 1);
548 const char input
[] = "0XP";
550 long double result
= UNINIT
;
551 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
553 ASSERT (result
== 0.0L);
554 ASSERT (!signbit (result
));
555 ASSERT (ptr
== input
+ 1);
559 const char input
[] = "0x.";
561 long double result
= UNINIT
;
562 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
564 ASSERT (result
== 0.0L);
565 ASSERT (!signbit (result
));
566 ASSERT (ptr
== input
+ 1);
570 const char input
[] = "0xp+";
572 long double result
= UNINIT
;
573 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
575 ASSERT (result
== 0.0L);
576 ASSERT (!signbit (result
));
577 ASSERT (ptr
== input
+ 1);
581 const char input
[] = "0xp+1";
583 long double result
= UNINIT
;
584 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
586 ASSERT (result
== 0.0L);
587 ASSERT (!signbit (result
));
588 ASSERT (ptr
== input
+ 1);
592 const char input
[] = "0x.p+1";
594 long double result
= UNINIT
;
595 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
597 ASSERT (result
== 0.0L);
598 ASSERT (!signbit (result
));
599 ASSERT (ptr
== input
+ 1);
603 const char input
[] = "1p+1";
605 long double result
= UNINIT
;
606 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
608 ASSERT (result
== 1.0L);
609 ASSERT (ptr
== input
+ 1);
613 const char input
[] = "1P+1";
615 long double result
= UNINIT
;
616 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
618 ASSERT (result
== 1.0L);
619 ASSERT (ptr
== input
+ 1);
625 const char input
[] = "1e6000";
627 long double result
= UNINIT
;
628 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
630 ASSERT (result
== HUGE_VALL
);
631 ASSERT (ptr
== input
+ 6);
632 ASSERT (errno
== ERANGE
);
635 const char input
[] = "1E1000000";
637 long double result
= UNINIT
;
638 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
640 ASSERT (result
== HUGE_VALL
);
641 ASSERT (ptr
== input
+ 9);
642 ASSERT (errno
== ERANGE
);
645 const char input
[] = "-1E1000000";
647 long double result
= UNINIT
;
648 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
650 ASSERT (result
== -HUGE_VALL
);
651 ASSERT (ptr
== input
+ 10);
652 ASSERT (errno
== ERANGE
);
655 /* Gradual underflow, resulting in a denormalized number. */
657 #if LDBL_MAX_EXP > 10000
658 const char input
[] = "1e-4950";
660 const char input
[] = "1e-320";
663 long double result
= UNINIT
;
664 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
666 ASSERT (0.0L < result
&& result
<= LDBL_MIN
);
667 ASSERT (ptr
== input
+ strlen (input
));
671 #if LDBL_MAX_EXP > 10000
672 const char input
[] = "-1e-4950";
674 const char input
[] = "-1e-320";
677 long double result
= UNINIT
;
678 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
680 ASSERT (-LDBL_MIN
<= result
&& result
< 0.0L);
681 ASSERT (ptr
== input
+ strlen (input
));
685 /* Flush-to-zero underflow. */
687 const char input
[] = "1E-100000";
689 long double result
= UNINIT
;
690 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
692 ASSERT (result
== 0.0L);
693 ASSERT (!signbit (result
));
694 ASSERT (ptr
== input
+ 9);
695 ASSERT (errno
== ERANGE
);
698 const char input
[] = "-1E-100000";
700 long double result
= UNINIT
;
701 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
703 ASSERT (result
== 0.0L);
704 /* Negative underflow. Expect a negative sign, although POSIX allows +0.0L.
705 See also <https://sourceware.org/bugzilla/show_bug.cgi?id=5995>. */
706 ASSERT (!!signbit (result
) == !!signbit (minus_zerol
));
707 ASSERT (ptr
== input
+ 10);
708 ASSERT (errno
== ERANGE
);
711 /* Space before the exponent. */
713 const char input
[] = "1E 1000000";
715 long double result
= UNINIT
;
716 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
718 ASSERT (result
== 1.0L);
719 ASSERT (ptr
== input
+ 1);
723 const char input
[] = "0x1P 1000000";
725 long double result
= UNINIT
;
726 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
728 ASSERT (result
== 1.0L);
729 ASSERT (ptr
== input
+ 3);
735 const char input
[] = "iNf";
737 long double result
= UNINIT
;
738 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
740 ASSERT (result
== HUGE_VALL
);
741 ASSERT (ptr
== input
+ 3);
745 const char input
[] = "-InF";
747 long double result
= UNINIT
;
748 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
750 ASSERT (result
== -HUGE_VALL
);
751 ASSERT (ptr
== input
+ 4);
755 const char input
[] = "infinite";
757 long double result
= UNINIT
;
758 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
760 ASSERT (result
== HUGE_VALL
);
761 ASSERT (ptr
== input
+ 3);
765 const char input
[] = "infinitY";
767 long double result
= UNINIT
;
768 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
770 ASSERT (result
== HUGE_VALL
);
771 ASSERT (ptr
== input
+ 8);
775 const char input
[] = "infinitY.";
777 long double result
= UNINIT
;
778 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
780 ASSERT (result
== HUGE_VALL
);
781 ASSERT (ptr
== input
+ 8);
785 /* NaN. Some processors set the sign bit of the default NaN, so all
786 we check is that using a sign changes the result. */
788 const char input
[] = "-nan";
791 long double result1
= UNINIT
;
792 long double result2
= UNINIT
;
793 bool ok1
= xstrtold (input
, &ptr1
, &result1
, strtold
);
794 bool ok2
= xstrtold (input
+ 1, &ptr2
, &result2
, strtold
);
797 #if 1 /* All known CPUs support NaNs. */
798 ASSERT (isnanl (result1
));
799 ASSERT (isnanl (result2
));
801 /* Sign bits of NaN is a portability sticking point, not worth
803 ASSERT (!!signbit (result1
) != !!signbit (result2
));
805 ASSERT (ptr1
== input
+ 4);
806 ASSERT (ptr2
== input
+ 4);
809 ASSERT (result1
== 0.0L);
810 ASSERT (result2
== 0.0L);
811 ASSERT (!signbit (result1
));
812 ASSERT (!signbit (result2
));
813 ASSERT (ptr1
== input
);
814 ASSERT (ptr2
== input
+ 1);
815 ASSERT (errno
== 0 || errno
== EINVAL
);
819 const char input
[] = "+nan(";
822 long double result1
= UNINIT
;
823 long double result2
= UNINIT
;
824 bool ok1
= xstrtold (input
, &ptr1
, &result1
, strtold
);
825 bool ok2
= xstrtold (input
+ 1, &ptr2
, &result2
, strtold
);
828 #if 1 /* All known CPUs support NaNs. */
829 ASSERT (isnanl (result1
));
830 ASSERT (isnanl (result2
));
831 ASSERT (!!signbit (result1
) == !!signbit (result2
));
832 ASSERT (ptr1
== input
+ 4);
833 ASSERT (ptr2
== input
+ 4);
836 ASSERT (result1
== 0.0L);
837 ASSERT (result2
== 0.0L);
838 ASSERT (!signbit (result1
));
839 ASSERT (!signbit (result2
));
840 ASSERT (ptr1
== input
);
841 ASSERT (ptr2
== input
+ 1);
842 ASSERT (errno
== 0 || errno
== EINVAL
);
846 const char input
[] = "-nan()";
849 long double result1
= UNINIT
;
850 long double result2
= UNINIT
;
851 bool ok1
= xstrtold (input
, &ptr1
, &result1
, strtold
);
852 bool ok2
= xstrtold (input
+ 1, &ptr2
, &result2
, strtold
);
855 #if 1 /* All known CPUs support NaNs. */
856 ASSERT (isnanl (result1
));
857 ASSERT (isnanl (result2
));
859 /* Sign bits of NaN is a portability sticking point, not worth
861 ASSERT (!!signbit (result1
) != !!signbit (result2
));
863 ASSERT (ptr1
== input
+ 6);
864 ASSERT (ptr2
== input
+ 6);
867 ASSERT (result1
== 0.0L);
868 ASSERT (result2
== 0.0L);
869 ASSERT (!signbit (result1
));
870 ASSERT (!signbit (result2
));
871 ASSERT (ptr1
== input
);
872 ASSERT (ptr2
== input
+ 1);
873 ASSERT (errno
== 0 || errno
== EINVAL
);
877 const char input
[] = " nan().";
879 long double result
= UNINIT
;
880 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
882 #if 1 /* All known CPUs support NaNs. */
883 ASSERT (isnanl (result
));
884 ASSERT (ptr
== input
+ 6);
887 ASSERT (result
== 0.0L);
888 ASSERT (!signbit (result
));
889 ASSERT (ptr
== input
);
890 ASSERT (errno
== 0 || errno
== EINVAL
);
894 /* The behavior of nan(0) is implementation-defined, but all
895 implementations we know of which handle optional
896 n-char-sequences handle nan(0) the same as nan(). */
897 const char input
[] = "-nan(0).";
900 long double result1
= UNINIT
;
901 long double result2
= UNINIT
;
902 bool ok1
= xstrtold (input
, &ptr1
, &result1
, strtold
);
903 bool ok2
= xstrtold (input
+ 1, &ptr2
, &result2
, strtold
);
906 #if 1 /* All known CPUs support NaNs. */
907 ASSERT (isnanl (result1
));
908 ASSERT (isnanl (result2
));
910 /* Sign bits of NaN is a portability sticking point, not worth
912 ASSERT (!!signbit (result1
) != !!signbit (result2
));
914 ASSERT (ptr1
== input
+ 7);
915 ASSERT (ptr2
== input
+ 7);
918 ASSERT (result1
== 0.0L);
919 ASSERT (result2
== 0.0L);
920 ASSERT (!signbit (result1
));
921 ASSERT (!signbit (result2
));
922 ASSERT (ptr1
== input
);
923 ASSERT (ptr2
== input
+ 1);
924 ASSERT (errno
== 0 || errno
== EINVAL
);
930 const char input
[] = "0xa";
932 long double result
= UNINIT
;
933 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
935 ASSERT (result
== 10.0L);
936 ASSERT (ptr
== input
+ 3);
940 const char input
[] = "0XA";
942 long double result
= UNINIT
;
943 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
945 ASSERT (result
== 10.0L);
946 ASSERT (ptr
== input
+ 3);
950 const char input
[] = "0x1p";
952 long double result
= UNINIT
;
953 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
955 ASSERT (result
== 1.0L);
956 ASSERT (ptr
== input
+ 3);
960 const char input
[] = "0x1p+";
962 long double result
= UNINIT
;
963 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
965 ASSERT (result
== 1.0L);
966 ASSERT (ptr
== input
+ 3);
970 const char input
[] = "0x1P+";
972 long double result
= UNINIT
;
973 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
975 ASSERT (result
== 1.0L);
976 ASSERT (ptr
== input
+ 3);
980 const char input
[] = "0x1p+1";
982 long double result
= UNINIT
;
983 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
985 ASSERT (result
== 2.0L);
986 ASSERT (ptr
== input
+ 6);
990 const char input
[] = "0X1P+1";
992 long double result
= UNINIT
;
993 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
995 ASSERT (result
== 2.0L);
996 ASSERT (ptr
== input
+ 6);
1000 const char input
[] = "0x1p+1a";
1002 long double result
= UNINIT
;
1003 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
1005 ASSERT (result
== 2.0L);
1006 ASSERT (ptr
== input
+ 6);
1007 ASSERT (errno
== 0);
1010 const char input
[] = "0x1p 2";
1012 long double result
= UNINIT
;
1013 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
1015 ASSERT (result
== 1.0L);
1016 ASSERT (ptr
== input
+ 3);
1017 ASSERT (errno
== 0);
1020 /* Large buffers. */
1023 char *input
= malloc (m
+ 1);
1027 long double result
= UNINIT
;
1028 memset (input
, '\t', m
- 1);
1031 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
1033 ASSERT (result
== 1.0L);
1034 ASSERT (ptr
== input
+ m
);
1035 ASSERT (errno
== 0);
1041 char *input
= malloc (m
+ 1);
1045 long double result
= UNINIT
;
1046 memset (input
, '0', m
- 1);
1049 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
1051 ASSERT (result
== 1.0L);
1052 ASSERT (ptr
== input
+ m
);
1053 ASSERT (errno
== 0);
1058 /* Newlib has an artificial limit of 20000 for the exponent. TODO -
1059 gnulib should fix this. */
1062 char *input
= malloc (m
+ 1);
1066 long double result
= UNINIT
;
1068 memset (input
+ 1, '0', m
- 10);
1079 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
1081 ASSERT (result
== 1.0L);
1082 ASSERT (ptr
== input
+ m
);
1083 ASSERT (errno
== 0);
1089 char *input
= malloc (m
+ 1);
1093 long double result
= UNINIT
;
1095 memset (input
+ 1, '0', m
- 9);
1105 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
1107 ASSERT (result
== 1.0L);
1108 ASSERT (ptr
== input
+ m
);
1109 ASSERT (errno
== 0);
1116 char *input
= malloc (m
+ 1);
1120 long double result
= UNINIT
;
1125 memset (input
+ 4, '0', m
- 3);
1127 bool ok
= xstrtold (input
, &ptr
, &result
, strtold
);
1129 ASSERT (result
== 0.0L);
1130 ASSERT (!!signbit (result
) == !!signbit (minus_zerol
));
1131 ASSERT (ptr
== input
+ m
);
1132 ASSERT (errno
== 0);
1137 return test_exit_status
;