Deleted Added
full compact
scanfloat_test.c (291840) scanfloat_test.c (291870)
1/*-
2 * Copyright (C) 2003, 2005 David Schultz <das@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * SUCH DAMAGE.
25 */
26
27/*
28 * Test for scanf() floating point formats.
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Copyright (C) 2003, 2005 David Schultz <das@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * SUCH DAMAGE.
25 */
26
27/*
28 * Test for scanf() floating point formats.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/scanfloat_test.c 291840 2015-12-05 04:17:40Z ngie $");
32__FBSDID("$FreeBSD: stable/10/lib/libc/tests/stdio/scanfloat_test.c 291870 2015-12-05 21:49:35Z ngie $");
33
34#include <fenv.h>
35#include <float.h>
36#include <locale.h>
37#include <math.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>

--- 12 unchanged lines hidden (view full) ---

53
54ATF_TC_WITHOUT_HEAD(normalized_numbers);
55ATF_TC_BODY(normalized_numbers, tc)
56{
57 char buf[128];
58 long double ld = 0.0;
59 double d = 0.0;
60 float f = 0.0;
33
34#include <fenv.h>
35#include <float.h>
36#include <locale.h>
37#include <math.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>

--- 12 unchanged lines hidden (view full) ---

53
54ATF_TC_WITHOUT_HEAD(normalized_numbers);
55ATF_TC_BODY(normalized_numbers, tc)
56{
57 char buf[128];
58 long double ld = 0.0;
59 double d = 0.0;
60 float f = 0.0;
61 char *endp;
62
63 buf[0] = '\0';
64 ATF_REQUIRE(setlocale(LC_NUMERIC, ""));
65
66 sscanf("3.141592", "%e", &f);
67 ATF_REQUIRE(eq(FLT, f, 3.141592));
68
69 sscanf("3.141592653589793", "%lf", &d);

--- 82 unchanged lines hidden (view full) ---

152
153ATF_TC_WITHOUT_HEAD(infinities_and_nans);
154ATF_TC_BODY(infinities_and_nans, tc)
155{
156 char buf[128];
157 long double ld = 0.0;
158 double d = 0.0;
159 float f = 0.0;
61
62 buf[0] = '\0';
63 ATF_REQUIRE(setlocale(LC_NUMERIC, ""));
64
65 sscanf("3.141592", "%e", &f);
66 ATF_REQUIRE(eq(FLT, f, 3.141592));
67
68 sscanf("3.141592653589793", "%lf", &d);

--- 82 unchanged lines hidden (view full) ---

151
152ATF_TC_WITHOUT_HEAD(infinities_and_nans);
153ATF_TC_BODY(infinities_and_nans, tc)
154{
155 char buf[128];
156 long double ld = 0.0;
157 double d = 0.0;
158 float f = 0.0;
160 char *endp;
161
162 ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
163
164 sscanf("-Inf", "%le", &d);
165 ATF_REQUIRE(d < 0.0 && isinf(d));
166
167 sscanf("iNfInItY and beyond", "%le%s", &d, buf);
168 ATF_REQUIRE(d > 0.0 && isinf(d));

--- 31 unchanged lines hidden (view full) ---

200 ATF_REQUIRE(ld != ld);
201 /* POSIX says we should only generate quiet NaNs. */
202 ATF_REQUIRE(fetestexcept(FE_INVALID) == 0);
203}
204
205ATF_TC_WITHOUT_HEAD(rounding_tests);
206ATF_TC_BODY(rounding_tests, tc)
207{
159
160 ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
161
162 sscanf("-Inf", "%le", &d);
163 ATF_REQUIRE(d < 0.0 && isinf(d));
164
165 sscanf("iNfInItY and beyond", "%le%s", &d, buf);
166 ATF_REQUIRE(d > 0.0 && isinf(d));

--- 31 unchanged lines hidden (view full) ---

198 ATF_REQUIRE(ld != ld);
199 /* POSIX says we should only generate quiet NaNs. */
200 ATF_REQUIRE(fetestexcept(FE_INVALID) == 0);
201}
202
203ATF_TC_WITHOUT_HEAD(rounding_tests);
204ATF_TC_BODY(rounding_tests, tc)
205{
208 char buf[128];
209 long double ld = 0.0;
210 double d = 0.0;
206 long double ld = 0.0;
207 double d = 0.0;
211 float f = 0.0;
212 char *endp;
213
214 ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
215
216 fesetround(FE_DOWNWARD);
217
218 sscanf("1.999999999999999999999999999999999", "%le", &d);
219 ATF_REQUIRE(d < 2.0);
220 sscanf("0x1.ffffffffffffffp0", "%le", &d);

--- 61 unchanged lines hidden (view full) ---

282 /* Extra digits in a denormal shouldn't break anything. */
283 sscanf("0x1.2345678p-1050", "%le", &d);
284 ATF_REQUIRE(d == 0x1.234568p-1050);
285}
286
287ATF_TC_WITHOUT_HEAD(strtod);
288ATF_TC_BODY(strtod, tc)
289{
208
209 ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
210
211 fesetround(FE_DOWNWARD);
212
213 sscanf("1.999999999999999999999999999999999", "%le", &d);
214 ATF_REQUIRE(d < 2.0);
215 sscanf("0x1.ffffffffffffffp0", "%le", &d);

--- 61 unchanged lines hidden (view full) ---

277 /* Extra digits in a denormal shouldn't break anything. */
278 sscanf("0x1.2345678p-1050", "%le", &d);
279 ATF_REQUIRE(d == 0x1.234568p-1050);
280}
281
282ATF_TC_WITHOUT_HEAD(strtod);
283ATF_TC_BODY(strtod, tc)
284{
290 char buf[128];
291 long double ld = 0.0;
292 double d = 0.0;
293 float f = 0.0;
294 char *endp;
295
296 ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
297
298 ATF_REQUIRE(strtod("0xy", &endp) == 0);
299 ATF_REQUIRE(strcmp("xy", endp) == 0);
300
301 /* This used to cause an infinite loop and round the wrong way. */

--- 24 unchanged lines hidden ---
285 char *endp;
286
287 ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
288
289 ATF_REQUIRE(strtod("0xy", &endp) == 0);
290 ATF_REQUIRE(strcmp("xy", endp) == 0);
291
292 /* This used to cause an infinite loop and round the wrong way. */

--- 24 unchanged lines hidden ---