mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
parent
e26bdbec52
commit
f064183646
48 changed files with 1034 additions and 921 deletions
|
@ -433,8 +433,7 @@ TEST(sprintf, test_float) {
|
|||
EXPECT_STREQ("3.5", Format("%.1f", 3.49));
|
||||
EXPECT_STREQ("a0.5 ", Format("a%-5.1f", 0.5));
|
||||
EXPECT_STREQ("a0.5 end", Format("a%-5.1fend", 0.5));
|
||||
/* out of range in the moment, need to be fixed by someone */
|
||||
EXPECT_STREQ("inf", Format("%.1f", 1E20));
|
||||
EXPECT_STREQ("100000000000000000000.0", Format("%.1f", 1E20));
|
||||
}
|
||||
|
||||
TEST(sprintf, test_types) {
|
||||
|
|
68
test/libc/fmt/realfmt_test.c
Normal file
68
test/libc/fmt/realfmt_test.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(RealFormatting, g) {
|
||||
EXPECT_STREQ("nan", gc(xasprintf("%g", NAN)));
|
||||
EXPECT_STREQ("-nan", gc(xasprintf("%g", -NAN)));
|
||||
EXPECT_STREQ("inf", gc(xasprintf("%g", INFINITY)));
|
||||
EXPECT_STREQ("-inf", gc(xasprintf("%g", -INFINITY)));
|
||||
EXPECT_STREQ("0", gc(xasprintf("%g", 0.)));
|
||||
EXPECT_STREQ("-0", gc(xasprintf("%g", -0.)));
|
||||
EXPECT_STREQ("1", gc(xasprintf("%g", 1.)));
|
||||
EXPECT_STREQ("-1", gc(xasprintf("%g", -1.)));
|
||||
EXPECT_STREQ("10", gc(xasprintf("%g", 10.)));
|
||||
EXPECT_STREQ("10", gc(xasprintf("%.0g", 10.)));
|
||||
EXPECT_STREQ("-10", gc(xasprintf("%g", -10.)));
|
||||
EXPECT_STREQ("-10", gc(xasprintf("%.0g", -10.)));
|
||||
EXPECT_STREQ(" -10", gc(xasprintf("%10g", -10.)));
|
||||
EXPECT_STREQ(" -10", gc(xasprintf("%*g", 10, -10.)));
|
||||
EXPECT_STREQ("1e+100", gc(xasprintf("%g", 1e100)));
|
||||
EXPECT_STREQ("1e-100", gc(xasprintf("%g", 1e-100)));
|
||||
EXPECT_STREQ("-1e-100", gc(xasprintf("%g", -1e-100)));
|
||||
EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
|
||||
}
|
||||
|
||||
TEST(RealFormatting, f) {
|
||||
EXPECT_STREQ("3.141593", gc(xasprintf("%f", 0x1.921fb54442d1846ap+1)));
|
||||
EXPECT_STREQ("3.1415926535897931",
|
||||
gc(xasprintf("%.16f", 0x1.921fb54442d1846ap+1)));
|
||||
EXPECT_STREQ("100000000000000001590289110975991804683608085639452813"
|
||||
"89781327557747838772170381060813469985856815104.000000",
|
||||
gc(xasprintf("%f", 1e100)));
|
||||
}
|
||||
|
||||
TEST(RealFormatting, e) {
|
||||
EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
|
||||
EXPECT_STREQ("3.141592653589793",
|
||||
gc(xasprintf("%.16g", 0x1.921fb54442d1846ap+1)));
|
||||
EXPECT_STREQ("1.000000e+100", gc(xasprintf("%e", 1e100)));
|
||||
EXPECT_STREQ("1.000000E+100", gc(xasprintf("%E", 1e100)));
|
||||
}
|
||||
|
||||
TEST(RealFormatting, a) {
|
||||
EXPECT_STREQ("0x1.921fb54442d18p+1",
|
||||
gc(xasprintf("%a", 0x1.921fb54442d1846ap+1)));
|
||||
EXPECT_STREQ("0X1.921FB54442D18P+1",
|
||||
gc(xasprintf("%A", 0x1.921fb54442d1846ap+1)));
|
||||
}
|
|
@ -29,6 +29,7 @@ TEST_LIBC_FMT_DIRECTDEPS = \
|
|||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue