From ac00be1a4e9fad56c9934c6332f381e631034ac0 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Tue, 30 Jun 2020 19:55:47 -0700 Subject: [PATCH] Make small fixes and oops ran clang-format on dtoa --- Makefile | 2 +- ape/ape.S | 8 +- ape/ape.lds | 2 +- ape/ape.mk | 13 +- ape/lib/pc.h | 8 +- build/do | 2 +- build/rules.mk | 3 +- examples/examples.mk | 3 +- examples/unbourne.c | 6 +- libc/bits/bits.h | 254 +- libc/bits/hamming.c | 4 +- libc/bits/{popcount.c => popcnt.c} | 22 +- libc/bits/popcnt.h | 24 + libc/calls/mprotect.greg.c | 4 +- libc/conv/conv.h | 2 +- libc/conv/strtoimax.c | 23 +- libc/fmt/palandftoa.c | 24 +- libc/log/meminfo.c | 3 + libc/macros.h | 1 - libc/macros.inc | 10 + libc/nexgen32e/doc/strcmp-avx2.c | 16 +- libc/rand/rdrand.c | 4 +- libc/runtime/balloc.c | 7 +- libc/runtime/missioncritical.h | 6 +- libc/stdio/fmemopen.c | 3 +- libc/stdio/setbuffer.c | 4 +- libc/stdio/setvbuf.c | 4 +- libc/tinymath/emodl.h | 17 + test/libc/conv/strtoimax_test.c | 22 +- test/libc/fmt/palandprintf_test.c | 2 +- test/libc/math/round_test.c | 16 +- test/libc/tinymath/round_test.c | 32 +- test/libc/unicode/wcwidth_test.c | 5 + third_party/compiler_rt/compiler_rt.mk | 2 +- third_party/dlmalloc/dlmalloc.c | 2 - third_party/dtoa/dtoa.c | 9340 ++++++++++++------------ third_party/dtoa/dtoa.h | 9 +- third_party/xed/avx.h | 43 + third_party/xed/avx512.h | 44 + third_party/xed/x86.h | 167 +- third_party/xed/x86ild.greg.c | 30 +- third_party/xed/x86tab.S | 26 +- tool/build/lib/interner.c | 2 +- tool/build/mkdeps.c | 2 +- tool/build/refactor.c | 1 + tool/decode/x86opinfo.c | 8 +- tool/viz/printvideo.c | 7 +- 47 files changed, 4933 insertions(+), 5306 deletions(-) rename libc/bits/{popcount.c => popcnt.c} (85%) create mode 100644 libc/bits/popcnt.h create mode 100644 libc/tinymath/emodl.h create mode 100644 third_party/xed/avx.h create mode 100644 third_party/xed/avx512.h diff --git a/Makefile b/Makefile index 5fb4b1df..6a3c3f5f 100644 --- a/Makefile +++ b/Makefile @@ -212,7 +212,7 @@ depend: o/$(MODE)/depend tags: TAGS HTAGS o/$(MODE)/.x: - @mkdir -p $(dir $@) && touch $@ + @$(MKDIR) $(dir $@) && touch $@ o/$(MODE)/srcs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(SRCS),$(dir $(x)))) $(file >$@) $(foreach x,$(SRCS),$(file >>$@,$(x))) diff --git a/ape/ape.S b/ape/ape.S index a29c9c4a..b92ed5fe 100644 --- a/ape/ape.S +++ b/ape/ape.S @@ -485,7 +485,6 @@ ape_disk: apesh: .ascii "'\n#'\"\n" # sixth edition shebang .ascii "o=\"$(command -v \"$0\")\"\n" - .ascii "set -- \"$o\" \"$@\"\n" .ascii "if [ -d /Applications ]; then\n" .ascii "dd if=\"$o\"" .ascii " of=\"$o\"" @@ -521,14 +520,17 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang .ascii "' >&7\n" .ascii "exec 7<&-\n" .ascii "fi\n" - .ascii "exec \"$@\"\n" # etxtbsy tail recursion + .ascii "exec \"$0\" \"$@\"\n" # etxtbsy tail recursion .ascii "R=$?\n" # architecture optimistic + .ascii "\n" .ascii "if [ $R -eq 126 ] && [ \"$(uname -m)\" != x86_64 ]; then\n" .ascii "if Q=\"$(command -v qemu-x86_64)\"; then\n" - .ascii "exec \"$Q\" \"$@\"\n" + .ascii "exec \"$Q\" \"$0\" \"$@\"\n" .ascii "else\n" .ascii "echo error: need qemu-x86_64 >&2\n" .ascii "fi\n" + .ascii "elif [ $R -eq 127 ]; then\n" # means argv[0] was wrong + .ascii " exec \"$o\" \"$@\"\n" # so do a path resolution .ascii "fi\n" .ascii "exit $R\n" .endobj apesh diff --git a/ape/ape.lds b/ape/ape.lds index 1d4d0438..d864c7e1 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -333,7 +333,7 @@ SECTIONS { /*BEGIN: Read only data that needn't be mapped after initialization */ /* Legal Notices */ -#ifndef IM_FEELING_NAUGHTY +#if !defined(IM_FEELING_NAUGHTY) || defined(EMBED_NOTICES) KEEP(*(.commentprologue)) KEEP(*(.comment)) KEEP(*(.commentepilogue)) diff --git a/ape/ape.mk b/ape/ape.mk index 997b1b88..06fc9d5c 100644 --- a/ape/ape.mk +++ b/ape/ape.mk @@ -21,6 +21,8 @@ APE = $(APE_DEPS) \ APELINK = \ ACTION=LINK.ape \ + $(MKDIR) \ + $(dir $@) && \ $(LINK) \ $(LINKARGS) \ $(OUTPUT_OPTION) && \ @@ -30,6 +32,15 @@ APELINK = \ $(ZFLAGS) \ -f $@.map +APECOPY = \ + ACTION=OBJCOPY.ape \ + TARGET=$@ \ + build/do \ + $(OBJCOPY) \ + -SO binary \ + $< \ + $@ + DEFAULT_COPTS += -mno-red-zone DEFAULT_LDFLAGS += -z max-page-size=0x1000 @@ -41,7 +52,7 @@ APE_DEPS = $(APE_LIB) APE_CHECKS = $(APE_HDRS:%=o/%.ok) o/%.com: o/%.com.dbg - @ACTION=OBJCOPY.ape TARGET=$@ build/do $(OBJCOPY) -SO binary $< $@ + @$(APECOPY) o/ape/idata.inc: \ ape/idata.h \ diff --git a/ape/lib/pc.h b/ape/lib/pc.h index fd1adeaa..cc4b38bd 100644 --- a/ape/lib/pc.h +++ b/ape/lib/pc.h @@ -148,12 +148,12 @@ 0b00000000000011111111111111111111111111111111111111000000000000 6666555555555544444444443333333333222222222211111111110000000000 3210987654321098765432109876543210987654321098765432109876543210*/ -#define PAGE_V /* */ 0b000000001 -#define PAGE_RW /* */ 0b000000010 -#define PAGE_U /* */ 0b000000100 +#define PAGE_V /* */ 0b000000001 +#define PAGE_RW /* */ 0b000000010 +#define PAGE_U /* */ 0b000000100 #define PAGE_2MB /* */ 0b110000000 #define PAGE_1GB /* */ 0b110000000 -#define PAGE_TA 0b011111111111111111111111111111111111111000000000000 +#define PAGE_TA 0b11111111111111111111111111111111111111000000000000 #define PAGE_PA2 0b11111111111111111111111111111000000000000000000000 #if !(__ASSEMBLER__ + __LINKER__ + 0) diff --git a/build/do b/build/do index 30b79fe9..36d4745d 100755 --- a/build/do +++ b/build/do @@ -16,7 +16,7 @@ MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit # Ensure directory creation if -o PATH flag is passed. -OUT= +OUT="$TARGET" FIRST=1 OUTARG=0 for x; do diff --git a/build/rules.mk b/build/rules.mk index 77772d48..f0aec677 100644 --- a/build/rules.mk +++ b/build/rules.mk @@ -33,7 +33,7 @@ o/%.inc: %.h; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) -D o/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^) o/%.h.ok: %.h; @ACTION=CHECK.h build/compile $(COMPILE.c) -x c -g0 -o $@ $< o/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $< -o/%.zip.o: %; @build/zipobj $(OUTPUT_OPTION) $< +o/%.zip.o: o/%; @build/zipobj $(OUTPUT_OPTION) $< o/$(MODE)/%.a:; @$(ARCHIVE) $@ $^ o/$(MODE)/%.o: %.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $< @@ -95,4 +95,3 @@ build/bootstrap/%.c.gz: %.rl @$(GZ) $(ZFLAGS) -f $(@:%.gz=%) %.svgz: %.rl @$(RAGEL) -V -p $< | $(DOT) -Tsvg | $(GZ) $(ZFLAGS) >$@ - diff --git a/examples/examples.mk b/examples/examples.mk index e510698d..b89c81b8 100644 --- a/examples/examples.mk +++ b/examples/examples.mk @@ -124,7 +124,8 @@ o/$(MODE)/examples/ispell.com.dbg: \ @$(APELINK) o/$(MODE)/usr/share/dict/words: usr/share/dict/words.gz - $(GZ) $(ZFLAGS) <$< >$@ + @$(MKDIR) $(dir $@) + @$(GZ) $(ZFLAGS) <$< >$@ .PHONY: o/$(MODE)/examples o/$(MODE)/examples: \ diff --git a/examples/unbourne.c b/examples/unbourne.c index 27671dfb..fc61eefb 100644 --- a/examples/unbourne.c +++ b/examples/unbourne.c @@ -606,11 +606,7 @@ #define printf out1fmt /* #define putc(c, file) outc(c, file) */ /* #define putchar(c) out1c(c) */ -#define FILE struct output -#undef fprintf -#define fprintf outfmt -#define fputs outstr -#define fflush flushout +#define FILE struct output #define fileno(f) ((f)->fd) /* #define ferror outerr */ #define INITARGS(argv) diff --git a/libc/bits/bits.h b/libc/bits/bits.h index 3a550e5c..4fc78f3f 100644 --- a/libc/bits/bits.h +++ b/libc/bits/bits.h @@ -16,7 +16,6 @@ extern const uint8_t kReverseBits[256]; uint16_t bswap_16(uint16_t) pureconst; uint32_t bswap_32(uint32_t) pureconst; uint32_t bswap_64(uint32_t) pureconst; -unsigned long popcount(unsigned long) pureconst; uint32_t gray(uint32_t) pureconst; uint32_t ungray(uint32_t) pureconst; unsigned bcdadd(unsigned, unsigned) pureconst; @@ -87,36 +86,36 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; }) #endif -#define WRITE16LE(P, V) \ - do { \ - uint8_t *Ple = (P); \ - uint16_t Vle = (V); \ - Ple[0] = (uint8_t)(Vle >> 000); \ - Ple[1] = (uint8_t)(Vle >> 010); \ +#define WRITE16LE(P, V) \ + do { \ + uint8_t *Ple = (unsigned char *)(P); \ + uint16_t Vle = (V); \ + Ple[0] = (uint8_t)(Vle >> 000); \ + Ple[1] = (uint8_t)(Vle >> 010); \ } while (0) -#define WRITE32LE(P, V) \ - do { \ - uint8_t *Ple = (P); \ - uint32_t Vle = (V); \ - Ple[0] = (uint8_t)(Vle >> 000); \ - Ple[1] = (uint8_t)(Vle >> 010); \ - Ple[2] = (uint8_t)(Vle >> 020); \ - Ple[3] = (uint8_t)(Vle >> 030); \ +#define WRITE32LE(P, V) \ + do { \ + uint8_t *Ple = (unsigned char *)(P); \ + uint32_t Vle = (V); \ + Ple[0] = (uint8_t)(Vle >> 000); \ + Ple[1] = (uint8_t)(Vle >> 010); \ + Ple[2] = (uint8_t)(Vle >> 020); \ + Ple[3] = (uint8_t)(Vle >> 030); \ } while (0) -#define WRITE64LE(P, V) \ - do { \ - uint8_t *Ple = (P); \ - uint64_t Vle = (V); \ - Ple[0] = (uint8_t)(Vle >> 000); \ - Ple[1] = (uint8_t)(Vle >> 010); \ - Ple[2] = (uint8_t)(Vle >> 020); \ - Ple[3] = (uint8_t)(Vle >> 030); \ - Ple[4] = (uint8_t)(Vle >> 040); \ - Ple[5] = (uint8_t)(Vle >> 050); \ - Ple[6] = (uint8_t)(Vle >> 060); \ - Ple[7] = (uint8_t)(Vle >> 070); \ +#define WRITE64LE(P, V) \ + do { \ + uint8_t *Ple = (unsigned char *)(P); \ + uint64_t Vle = (V); \ + Ple[0] = (uint8_t)(Vle >> 000); \ + Ple[1] = (uint8_t)(Vle >> 010); \ + Ple[2] = (uint8_t)(Vle >> 020); \ + Ple[3] = (uint8_t)(Vle >> 030); \ + Ple[4] = (uint8_t)(Vle >> 040); \ + Ple[5] = (uint8_t)(Vle >> 050); \ + Ple[6] = (uint8_t)(Vle >> 060); \ + Ple[7] = (uint8_t)(Vle >> 070); \ } while (0) /* TODO(jart): these ones aren't coded correctly */ @@ -135,27 +134,27 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; * @note we beseech clang devs for flag constraints */ #ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */ -#define CF "=@ccc" -#define CFLAG(OP) OP -#define ZF "=@ccz" -#define ZFLAG(OP) OP -#define OF "=@cco" -#define OFLAG(OP) OP -#define SF "=@ccs" -#define SFLAG(SP) SP -#define ABOVEF "=@cca" /* i.e. !ZF && !CF */ -#define ABOVEFLAG(OP) OP +#define CFLAG_CONSTRAINT "=@ccc" +#define CFLAG_ASM(OP) OP +#define ZFLAG_CONSTRAINT "=@ccz" +#define ZFLAG_ASM(OP) OP +#define OFLAG_CONSTRAINT "=@cco" +#define OFLAG_ASM(OP) OP +#define SFLAG_CONSTRAINT "=@ccs" +#define SFLAG_ASM(SP) SP +#define ABOVE_CONSTRAINT "=@cca" /* i.e. !ZF && !CF */ +#define ABOVEFLAG_ASM(OP) OP #else -#define CF "=q" -#define CFLAG(OP) OP "\n\tsetc\t%b0" -#define ZF "=q" -#define ZFLAG(OP) OP "\n\tsetz\t%b0" -#define OF "=q" -#define OFLAG(OP) OP "\n\tseto\t%b0" -#define SF "=q" -#define SFLAG(SP) OP "\n\tsets\t%b0" -#define ABOVEF "=@cca" -#define ABOVEFLAG(OP) OP "\n\tseta\t%b0" +#define CFLAG_CONSTRAINT "=q" +#define CFLAG_ASM(OP) OP "\n\tsetc\t%b0" +#define ZFLAG_CONSTRAINT "=q" +#define ZFLAG_ASM(OP) OP "\n\tsetz\t%b0" +#define OFLAG_CONSTRAINT "=q" +#define OFLAG_ASM(OP) OP "\n\tseto\t%b0" +#define SFLAG_CONSTRAINT "=q" +#define SFLAG_ASM(SP) OP "\n\tsets\t%b0" +#define ABOVE_CONSTRAINT "=@cca" +#define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0" #endif /** @@ -226,23 +225,32 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; * @see Intel's Six Thousand Page Manual V.2A 3-113 * @see bts(), btr(), btc() */ -#define bt(MEM, BIT) \ - ({ \ - bool OldBit; \ - if (isconstant(BIT)) { \ - asm(CFLAG("bt%z1\t%2,%1") \ - : CF(OldBit) \ - : "m"((MEM)[(BIT) / (sizeof((MEM)[0]) * CHAR_BIT)]), \ - "J"((BIT) % (sizeof((MEM)[0]) * CHAR_BIT)) \ - : "cc"); \ - } else if (sizeof((MEM)[0]) == 2) { \ - asm(CFLAG("bt\t%w2,%1") : CF(OldBit) : "m"((MEM)[0]), "r"(BIT) : "cc"); \ - } else if (sizeof((MEM)[0]) == 4) { \ - asm(CFLAG("bt\t%k2,%1") : CF(OldBit) : "m"((MEM)[0]), "r"(BIT) : "cc"); \ - } else if (sizeof((MEM)[0]) == 8) { \ - asm(CFLAG("bt\t%q2,%1") : CF(OldBit) : "m"((MEM)[0]), "r"(BIT) : "cc"); \ - } \ - OldBit; \ +#define bt(MEM, BIT) \ + ({ \ + bool OldBit; \ + if (isconstant(BIT)) { \ + asm(CFLAG_ASM("bt%z1\t%2,%1") \ + : CFLAG_CONSTRAINT(OldBit) \ + : "m"((MEM)[(BIT) / (sizeof((MEM)[0]) * CHAR_BIT)]), \ + "J"((BIT) % (sizeof((MEM)[0]) * CHAR_BIT)) \ + : "cc"); \ + } else if (sizeof((MEM)[0]) == 2) { \ + asm(CFLAG_ASM("bt\t%w2,%1") \ + : CFLAG_CONSTRAINT(OldBit) \ + : "m"((MEM)[0]), "r"(BIT) \ + : "cc"); \ + } else if (sizeof((MEM)[0]) == 4) { \ + asm(CFLAG_ASM("bt\t%k2,%1") \ + : CFLAG_CONSTRAINT(OldBit) \ + : "m"((MEM)[0]), "r"(BIT) \ + : "cc"); \ + } else if (sizeof((MEM)[0]) == 8) { \ + asm(CFLAG_ASM("bt\t%q2,%1") \ + : CFLAG_CONSTRAINT(OldBit) \ + : "m"((MEM)[0]), "r"(BIT) \ + : "cc"); \ + } \ + OldBit; \ }) #define bts(MEM, BIT) __BitOp("bts", BIT, MEM) /** bit test and set */ @@ -285,27 +293,27 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; * @return true if value was exchanged, otherwise false * @see lockcmpxchg() */ -#define cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ - ({ \ - bool DidIt; \ - asm(ZFLAG("cmpxchg\t%3,%1") \ - : ZF(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \ - : "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \ - : "cc"); \ - DidIt; \ +#define cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ + ({ \ + bool DidIt; \ + asm(ZFLAG_ASM("cmpxchg\t%3,%1") \ + : ZFLAG_CONSTRAINT(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \ + : "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \ + : "cc"); \ + DidIt; \ }) -#define ezcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ - ({ \ - bool DidIt; \ - autotype(IFTHING) IfThing = (IFTHING); \ - typeof(*IfThing) IsEqualToMe = (ISEQUALTOME); \ - typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME); \ - asm(ZFLAG("cmpxchg\t%3,%1") \ - : ZF(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \ - : "r"(ReplaceItWithMe) \ - : "cc"); \ - DidIt; \ +#define ezcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ + ({ \ + bool DidIt; \ + autotype(IFTHING) IfThing = (IFTHING); \ + typeof(*IfThing) IsEqualToMe = (ISEQUALTOME); \ + typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME); \ + asm(ZFLAG_ASM("cmpxchg\t%3,%1") \ + : ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \ + : "r"(ReplaceItWithMe) \ + : "cc"); \ + DidIt; \ }) /** @@ -315,14 +323,14 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; * @return true if value was exchanged, otherwise false * @see lockcmpxchg() */ -#define lockcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ - ({ \ - bool DidIt; \ - asm(ZFLAG("lock cmpxchg\t%3,%1") \ - : ZF(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \ - : "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \ - : "cc"); \ - DidIt; \ +#define lockcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \ + ({ \ + bool DidIt; \ + asm(ZFLAG_ASM("lock cmpxchg\t%3,%1") \ + : ZFLAG_CONSTRAINT(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \ + : "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \ + : "cc"); \ + DidIt; \ }) /** @@ -431,19 +439,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; ╚────────────────────────────────────────────────────────────────────────────│*/ #if defined(__GNUC__) && !defined(__STRICT_ANSI__) -#define popcount(X) (isconstant(X) ? __builtin_popcount(X) : __popcount(X)) -#define popcount$nehalem(X) \ - ({ \ - typeof(X) BitCount; \ - asm("popcnt\t%1,%0" : "=r,r"(BitCount) : "r,m"(X) : "cc"); \ - BitCount; \ - }) -#ifdef __POPCNT__ -#define __popcount(X) popcount$nehalem(X) -#else -#define __popcount(X) (popcount)(X) -#endif - #define bswap_16(U16) \ (isconstant(U16) ? ((((U16)&0xff00) >> 010) | (((U16)&0x00ff) << 010)) : ({ \ uint16_t Swapped16, Werd16 = (U16); \ @@ -500,31 +495,32 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; MEM; \ }) -#define __BitOp(OP, BIT, MEM) \ - ({ \ - bool OldBit; \ - if (isconstant(BIT)) { \ - asm(CFLAG(OP "%z1\t%2,%1") \ - : CF(OldBit), "+m"((MEM)[(BIT) / (sizeof((MEM)[0]) * CHAR_BIT)]) \ - : "J"((BIT) % (sizeof((MEM)[0]) * CHAR_BIT)) \ - : "cc"); \ - } else if (sizeof((MEM)[0]) == 2) { \ - asm(CFLAG(OP "\t%w2,%1") \ - : CF(OldBit), "+m"((MEM)[0]) \ - : "r"(BIT) \ - : "cc"); \ - } else if (sizeof((MEM)[0]) == 4) { \ - asm(CFLAG(OP "\t%k2,%1") \ - : CF(OldBit), "+m"((MEM)[0]) \ - : "r"(BIT) \ - : "cc"); \ - } else if (sizeof((MEM)[0]) == 8) { \ - asm(CFLAG(OP "\t%q2,%1") \ - : CF(OldBit), "+m"((MEM)[0]) \ - : "r"(BIT) \ - : "cc"); \ - } \ - OldBit; \ +#define __BitOp(OP, BIT, MEM) \ + ({ \ + bool OldBit; \ + if (isconstant(BIT)) { \ + asm(CFLAG_ASM(OP "%z1\t%2,%1") \ + : CFLAG_CONSTRAINT(OldBit), \ + "+m"((MEM)[(BIT) / (sizeof((MEM)[0]) * CHAR_BIT)]) \ + : "J"((BIT) % (sizeof((MEM)[0]) * CHAR_BIT)) \ + : "cc"); \ + } else if (sizeof((MEM)[0]) == 2) { \ + asm(CFLAG_ASM(OP "\t%w2,%1") \ + : CFLAG_CONSTRAINT(OldBit), "+m"((MEM)[0]) \ + : "r"(BIT) \ + : "cc"); \ + } else if (sizeof((MEM)[0]) == 4) { \ + asm(CFLAG_ASM(OP "\t%k2,%1") \ + : CFLAG_CONSTRAINT(OldBit), "+m"((MEM)[0]) \ + : "r"(BIT) \ + : "cc"); \ + } else if (sizeof((MEM)[0]) == 8) { \ + asm(CFLAG_ASM(OP "\t%q2,%1") \ + : CFLAG_CONSTRAINT(OldBit), "+m"((MEM)[0]) \ + : "r"(BIT) \ + : "cc"); \ + } \ + OldBit; \ }) COSMOPOLITAN_C_END_ diff --git a/libc/bits/hamming.c b/libc/bits/hamming.c index 38beb33a..0e9807d6 100644 --- a/libc/bits/hamming.c +++ b/libc/bits/hamming.c @@ -17,11 +17,11 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bits.h" +#include "libc/bits/popcnt.h" /** * Counts number of different bits. */ unsigned long hamming(unsigned long x, unsigned long y) { - return popcount(x ^ y); + return popcnt(x ^ y); } diff --git a/libc/bits/popcount.c b/libc/bits/popcnt.c similarity index 85% rename from libc/bits/popcount.c rename to libc/bits/popcnt.c index d201846a..532ada5c 100644 --- a/libc/bits/popcount.c +++ b/libc/bits/popcnt.c @@ -17,26 +17,20 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bits.h" -#include "libc/nexgen32e/x86feature.h" +#include "libc/bits/popcnt.h" -static noinline uint32_t popcount$swar32(uint32_t x) { +static uint32_t popcnt32(uint32_t x) { x -= (x >> 1) & 0x55555555; x = (x & 0x33333333) + ((x >> 2) & 0x33333333); return (((x + (x >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; } -unsigned long(popcount)(unsigned long x) { - size_t i; +unsigned long(popcnt)(unsigned long x) { unsigned long r; - if (X86_HAVE(POPCNT)) { - return popcount$nehalem(x); - } else { - r = 0; - for (i = 0; i < sizeof(x); i += 4) { - r |= popcount$swar32(x); - x >>= 32; - } - return r; + r = 0; + while (x) { + r += popcnt32(x); + x >>= 32; } + return r; } diff --git a/libc/bits/popcnt.h b/libc/bits/popcnt.h new file mode 100644 index 00000000..0af8af80 --- /dev/null +++ b/libc/bits/popcnt.h @@ -0,0 +1,24 @@ +#ifndef COSMOPOLITAN_LIBC_BITS_POPCNT_H_ +#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_ +#include "libc/nexgen32e/x86feature.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +unsigned long popcnt(unsigned long) pureconst; + +#if defined(__GNUC__) && !defined(__STRICT_ANSI__) +#define popcnt(X) \ + (isconstant(X) ? __builtin_popcount(X) : ({ \ + unsigned long Res, Pop = (X); \ + if (X86_HAVE(POPCNT)) { \ + asm("popcnt\t%1,%0" : "=r"(Res) : "r"(Pop) : "cc"); \ + } else { \ + Res = (popcnt)(Pop); \ + } \ + Res; \ + })) +#endif /* GNUC && !ANSI */ + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_BITS_POPCNT_H_ */ diff --git a/libc/calls/mprotect.greg.c b/libc/calls/mprotect.greg.c index 1427364c..3f516435 100644 --- a/libc/calls/mprotect.greg.c +++ b/libc/calls/mprotect.greg.c @@ -32,8 +32,8 @@ privileged int __mprotect(void *addr, uint64_t len, int prot) { int64_t rc; uint32_t oldprot; if (!IsWindows()) { - asm volatile(CFLAG("syscall") - : CF(cf), "=a"(rc) + asm volatile(CFLAG_ASM("syscall") + : CFLAG_CONSTRAINT(cf), "=a"(rc) : "1"(__NR_mprotect), "D"(addr), "S"(len), "d"(prot) : "rcx", "r11", "memory", "cc"); if (cf) { diff --git a/libc/conv/conv.h b/libc/conv/conv.h index 353ed022..6b8c5ae3 100644 --- a/libc/conv/conv.h +++ b/libc/conv/conv.h @@ -30,7 +30,7 @@ unsigned long strtoul(const char *, char **, int) paramsnonnull((1)); long long strtoll(const char *, char **, int) paramsnonnull((1)); unsigned long long strtoull(const char *, char **, int) paramsnonnull((1)); long long strtonum(const char *, long long, long long, const char **); -intmax_t div10(intmax_t x, unsigned *rem) hidden; +intmax_t div10(intmax_t, unsigned *) hidden; intmax_t strtoimax(const char *, char **, int) paramsnonnull((1)); uintmax_t strtoumax(const char *, char **, int) paramsnonnull((1)); intmax_t wcstoimax(const wchar_t *, wchar_t **, int); diff --git a/libc/conv/strtoimax.c b/libc/conv/strtoimax.c index c93576a4..a4efc27e 100644 --- a/libc/conv/strtoimax.c +++ b/libc/conv/strtoimax.c @@ -37,10 +37,10 @@ * @see strtoumax */ intmax_t strtoimax(const char *s, char **endptr, int base) { - bool neg; uintmax_t x; intmax_t res; unsigned diglet, bits; + bool neg, islong, isunsigned; x = 0; bits = 0; @@ -100,10 +100,23 @@ intmax_t strtoimax(const char *s, char **endptr, int base) { } } - if (endptr) { - *endptr = s; + if ((isunsigned = *s == 'u' || *s == 'U')) s++; + if ((islong = *s == 'l' || *s == 'L')) s++; + if (endptr) *endptr = s; + + if (neg) { + res = -x; + } else { + res = x; } - res = x; - return neg ? -res : res; + if (isunsigned) { + if (islong) { + res = (uint64_t)res; + } else { + res = (uint32_t)res; + } + } + + return res; } diff --git a/libc/fmt/palandftoa.c b/libc/fmt/palandftoa.c index 0cf3974d..04b46a06 100644 --- a/libc/fmt/palandftoa.c +++ b/libc/fmt/palandftoa.c @@ -54,23 +54,17 @@ int ftoa(int out(int, void *), void *arg, long double value, unsigned long prec, diff = 0; if (isnan(value)) { - buf[0] = 'N'; - buf[1] = 'A'; - buf[2] = 'N'; + buf[0] = 'n'; + buf[1] = 'a'; + buf[2] = 'n'; + buf[3] = '\0'; + len += 3; + } else if (isinf(value) || fabsl(value) > 0x7ffffffffffffffful) { + buf[0] = 'f'; + buf[1] = 'n'; + buf[2] = 'i'; buf[3] = '\0'; len += 3; - } else if (isinf(value) || - (/* TODO(jart): need this? */ fabsl(value) > 0x7fffffff)) { - buf[0] = 'Y'; - buf[1] = 'T'; - buf[2] = 'I'; - buf[3] = 'N'; - buf[4] = 'I'; - buf[5] = 'F'; - buf[6] = 'N'; - buf[7] = 'I'; - buf[8] = '\0'; - len += 8; } else { /* set default precision to 6, if not set explicitly */ diff --git a/libc/log/meminfo.c b/libc/log/meminfo.c index e3399562..5edd3d0f 100644 --- a/libc/log/meminfo.c +++ b/libc/log/meminfo.c @@ -31,6 +31,9 @@ static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) { (intptr_t)end - (intptr_t)start); } +/** + * Prints memory mappings. + */ void meminfo(FILE *f) { memsummary(f); (fprintf)(f, "%*s %*s %*s %*s\n", POINTER_XDIGITS, "start", diff --git a/libc/macros.h b/libc/macros.h index ce3d06a1..e3009eb2 100644 --- a/libc/macros.h +++ b/libc/macros.h @@ -20,7 +20,6 @@ #define ABS(X) ((X) >= 0 ? (X) : -(X)) #define MIN(X, Y) ((Y) > (X) ? (X) : (Y)) #define MAX(X, Y) ((Y) < (X) ? (X) : (Y)) -#define MOD(X, Y) ((X) - (ABS(Y)) * ((X) / ABS(Y))) #define PASTE(A, B) __PASTE(A, B) #define STRINGIFY(A) __STRINGIFY(A) #define EQUIVALENT(X, Y) (isconstant((X) == (Y)) && ((X) == (Y))) diff --git a/libc/macros.inc b/libc/macros.inc index dd9e20a5..d6f860ea 100644 --- a/libc/macros.inc +++ b/libc/macros.inc @@ -264,6 +264,16 @@ _init_\name: .popsection .endm +/ ICE Breakpoint. +/ Modern gas forgot this but objdump knows +/ @mode long,legacy,real + .macro icebp + .byte 0xF1 + .endm + .macro int1 + icebp + .endm + / Sets breakpoint for software debugger. / @mode long,legacy,real .macro .softicebp diff --git a/libc/nexgen32e/doc/strcmp-avx2.c b/libc/nexgen32e/doc/strcmp-avx2.c index e93d0c85..b678d487 100644 --- a/libc/nexgen32e/doc/strcmp-avx2.c +++ b/libc/nexgen32e/doc/strcmp-avx2.c @@ -41,14 +41,14 @@ bLoop: vbitmask_t r1; uint8_v v1, v2; const uint8_v kZero = {0}; - asm(ZFLAG("vmovdqu\t%5,%2\n\t" /* move because gcc problematic */ - "vpcmpeqb\t%4,%2,%1\n\t" /* check for equality in p1 and p2 */ - "vpcmpeqb\t%6,%2,%2\n\t" /* check for nul in p1 */ - "vpandn\t%7,%1,%2\n\t" /* most complicated bitwise not ever */ - "vpor\t%2,%1,%1\n\t" /* check for nul in p2 */ - "pmovmskb\t%1,%3\n\t" /* turn 256 bits into 32 bits */ - "bsf\t%3,%3") /* find stop byte */ - : ZF(zf), "=x"(v1), "=x"(v2), "=r"(r1) + asm(ZFLAG_ASM("vmovdqu\t%5,%2\n\t" /* move because gcc problematic */ + "vpcmpeqb\t%4,%2,%1\n\t" /* check for equality in p1 and p2 */ + "vpcmpeqb\t%6,%2,%2\n\t" /* check for nul in p1 */ + "vpandn\t%7,%1,%2\n\t" /* most complicated bitwise not ever */ + "vpor\t%2,%1,%1\n\t" /* check for nul in p2 */ + "pmovmskb\t%1,%3\n\t" /* turn 256 bits into 32 bits */ + "bsf\t%3,%3") /* find stop byte */ + : ZFLAG_CONSTRAINT(zf), "=x"(v1), "=x"(v2), "=r"(r1) : "m"(*(const uint8_v *)(p1 + i)), "m"(*(const uint8_v *)(p2 + i)), "x"(kZero), "m"(kVectorSize)); if (zf) goto vLoop; diff --git a/libc/rand/rdrand.c b/libc/rand/rdrand.c index e359265d..f6ae4dda 100644 --- a/libc/rand/rdrand.c +++ b/libc/rand/rdrand.c @@ -36,8 +36,8 @@ uint64_t rdrand(void) { for (;;) { for (i = 0; i < 10; ++i) { /* CF=1: Destination register valid. Quoth Intel DRNG-SIG 4.1.3 */ - asm volatile(CFLAG("rdrand\t%1") - : CF(cf), "=r"(res) + asm volatile(CFLAG_ASM("rdrand\t%1") + : CFLAG_CONSTRAINT(cf), "=r"(res) : /* no inputs */ : "cc"); if (cf) return res; diff --git a/libc/runtime/balloc.c b/libc/runtime/balloc.c index 377d73b0..c5078c42 100644 --- a/libc/runtime/balloc.c +++ b/libc/runtime/balloc.c @@ -19,6 +19,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" #include "libc/bits/bits.h" +#include "libc/bits/popcnt.h" #include "libc/bits/safemacros.h" #include "libc/calls/calls.h" #include "libc/runtime/buffer.h" @@ -54,9 +55,9 @@ void *balloc(struct GuardedBuffer *b, unsigned a, size_t n) { assert(a >= 1); assert(a <= kGuard); assert(kGuard < kGrain); - assert(popcount(a) == 1); - assert(popcount(kGuard) == 1); - assert(popcount(kGrain) == 1); + assert(popcnt(a) == 1); + assert(popcnt(kGuard) == 1); + assert(popcnt(kGrain) == 1); assert(n < 0x800000000000ul - kGrain - kGuard); if (n) { diff --git a/libc/runtime/missioncritical.h b/libc/runtime/missioncritical.h index bbb9b33a..047e0718 100644 --- a/libc/runtime/missioncritical.h +++ b/libc/runtime/missioncritical.h @@ -45,9 +45,9 @@ ({ \ int KillAx; \ unsigned char Cf; \ - asm volatile(CFLAG("clc\n\t" \ - "syscall") \ - : CF(Cf), "=a"(KillAx) \ + asm volatile(CFLAG_ASM("clc\n\t" \ + "syscall") \ + : CFLAG_CONSTRAINT(Cf), "=a"(KillAx) \ : "1"(__NR_kill), "D"(pid), "S"(sig) \ : "rcx", "r11", "cc", "memory"); \ Cf ? -KillAx : KillAx; \ diff --git a/libc/stdio/fmemopen.c b/libc/stdio/fmemopen.c index 16e5705c..92672951 100644 --- a/libc/stdio/fmemopen.c +++ b/libc/stdio/fmemopen.c @@ -18,6 +18,7 @@ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/bits/bits.h" +#include "libc/bits/popcnt.h" #include "libc/calls/calls.h" #include "libc/errno.h" #include "libc/mem/mem.h" @@ -46,7 +47,7 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) { return NULL; } - if (size && popcount(size) != 1) { + if (size && popcnt(size) != 1) { einval(); return NULL; } diff --git a/libc/stdio/setbuffer.c b/libc/stdio/setbuffer.c index 0fe48231..43a1be24 100644 --- a/libc/stdio/setbuffer.c +++ b/libc/stdio/setbuffer.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bits.h" +#include "libc/bits/popcnt.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/sysv/errfuns.h" @@ -26,7 +26,7 @@ * Sets buffer on stdio stream. */ void setbuffer(FILE *f, char *buf, size_t size) { - if (size && popcount(size) != 1) abort(); + if (size && popcnt(size) != 1) abort(); if (buf && f->buf != (unsigned char *)buf) { free_s(&f->buf); if (!size) size = BUFSIZ; diff --git a/libc/stdio/setvbuf.c b/libc/stdio/setvbuf.c index bcf5dc8d..476d9448 100644 --- a/libc/stdio/setvbuf.c +++ b/libc/stdio/setvbuf.c @@ -17,7 +17,7 @@ │ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │ │ 02110-1301 USA │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/bits/bits.h" +#include "libc/bits/popcnt.h" #include "libc/stdio/stdio.h" #include "libc/sysv/errfuns.h" @@ -31,7 +31,7 @@ * @return 0 on success or -1 on error */ int setvbuf(FILE *f, char *buf, int mode, size_t size) { - if (size && popcount(size) != 1) return einval(); + if (size && popcnt(size) != 1) return einval(); setbuffer(f, buf, size); f->bufmode = mode; return 0; diff --git a/libc/tinymath/emodl.h b/libc/tinymath/emodl.h new file mode 100644 index 00000000..7a5656df --- /dev/null +++ b/libc/tinymath/emodl.h @@ -0,0 +1,17 @@ +#ifndef COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_ +#define COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_ +#include "libc/math.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) + +/** + * Returns Euclidean floating-point division remainder. + * + * @return (𝑥 mod 𝑦) ∈ [0.,𝑦) + * @see fmodl() + */ +static long double emodl(long double x, long double y) { + return x - fabsl(y) * floorl(x / fabsl(y)); +} + +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_ */ diff --git a/test/libc/conv/strtoimax_test.c b/test/libc/conv/strtoimax_test.c index e7406a4c..f727e167 100644 --- a/test/libc/conv/strtoimax_test.c +++ b/test/libc/conv/strtoimax_test.c @@ -23,10 +23,18 @@ /* todo(jart): work on this more */ -TEST(strtoimax, testZero) { EXPECT_EQ(0, strtoimax("0", NULL, 0)); } -TEST(strtoimax, testDecimal) { EXPECT_EQ(-123, strtoimax("-123", NULL, 0)); } -TEST(strtoimax, testHex) { EXPECT_EQ(-255, strtoimax("-0xff", NULL, 0)); } -TEST(strtoimax, testOctal) { EXPECT_EQ(-123, strtoimax("-0173", NULL, 0)); } +TEST(strtoimax, testZero) { + EXPECT_EQ(0, strtoimax("0", NULL, 0)); +} +TEST(strtoimax, testDecimal) { + EXPECT_EQ(-123, strtoimax("-123", NULL, 0)); +} +TEST(strtoimax, testHex) { + EXPECT_EQ(-255, strtoimax("-0xff", NULL, 0)); +} +TEST(strtoimax, testOctal) { + EXPECT_EQ(-123, strtoimax("-0173", NULL, 0)); +} TEST(strtoimax, testLimits) { EXPECT_EQ( @@ -36,3 +44,9 @@ TEST(strtoimax, testLimits) { ((uintmax_t)0x7fffffffffffffff) << 64 | (uintmax_t)0xffffffffffffffff, strtoimax("0x7fffffffffffffffffffffffffffffff", NULL, 0)); } + +TEST(strtoimax, testZeroExtend) { + EXPECT_EQ(-1, strtoimax("-1", NULL, 0)); + EXPECT_EQ(0xffffffff, strtoimax("-1u", NULL, 0)); + EXPECT_EQ(0xffffffffffffffff, strtoimax("-1ul", NULL, 0)); +} diff --git a/test/libc/fmt/palandprintf_test.c b/test/libc/fmt/palandprintf_test.c index 853263b4..b051dc27 100644 --- a/test/libc/fmt/palandprintf_test.c +++ b/test/libc/fmt/palandprintf_test.c @@ -434,7 +434,7 @@ TEST(sprintf, test_float) { 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("INFINITY", Format("%.1f", 1E20)); + EXPECT_STREQ("inf", Format("%.1f", 1E20)); } TEST(sprintf, test_types) { diff --git a/test/libc/math/round_test.c b/test/libc/math/round_test.c index 5fa65779..740902c0 100644 --- a/test/libc/math/round_test.c +++ b/test/libc/math/round_test.c @@ -33,10 +33,10 @@ TEST(round, test) { TEST(round, testCornerCases) { EXPECT_STREQ("-0", gc(xdtoa(round(-0.0)))); - EXPECT_STREQ("NAN", gc(xdtoa(round(NAN)))); - EXPECT_STREQ("-NAN", gc(xdtoa(round(-NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(round(INFINITY)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(round(-INFINITY)))); + EXPECT_STREQ("nan", gc(xdtoa(round(NAN)))); + EXPECT_STREQ("-nan", gc(xdtoa(round(-NAN)))); + EXPECT_STREQ("inf", gc(xdtoa(round(INFINITY)))); + EXPECT_STREQ("-inf", gc(xdtoa(round(-INFINITY)))); } TEST(lround, test) { @@ -60,10 +60,10 @@ TEST(roundf, test) { TEST(roundf, testCornerCases) { EXPECT_STREQ("-0", gc(xdtoa(roundf(-0.0)))); - EXPECT_STREQ("NAN", gc(xdtoa(roundf(NAN)))); - EXPECT_STREQ("-NAN", gc(xdtoa(roundf(-NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(roundf(INFINITY)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(roundf(-INFINITY)))); + EXPECT_STREQ("nan", gc(xdtoa(roundf(NAN)))); + EXPECT_STREQ("-nan", gc(xdtoa(roundf(-NAN)))); + EXPECT_STREQ("inf", gc(xdtoa(roundf(INFINITY)))); + EXPECT_STREQ("-inf", gc(xdtoa(roundf(-INFINITY)))); } TEST(lroundf, test) { diff --git a/test/libc/tinymath/round_test.c b/test/libc/tinymath/round_test.c index 44dede04..e189424d 100644 --- a/test/libc/tinymath/round_test.c +++ b/test/libc/tinymath/round_test.c @@ -38,10 +38,10 @@ TEST(round, test) { TEST(round, testCornerCases) { EXPECT_STREQ("-0", gc(xdtoa(tinymath_round(-0.0)))); - EXPECT_STREQ("NAN", gc(xdtoa(tinymath_round(NAN)))); - EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_round(-NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_round(INFINITY)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_round(-INFINITY)))); + EXPECT_STREQ("nan", gc(xdtoa(tinymath_round(NAN)))); + EXPECT_STREQ("-nan", gc(xdtoa(tinymath_round(-NAN)))); + EXPECT_STREQ("inf", gc(xdtoa(tinymath_round(INFINITY)))); + EXPECT_STREQ("-inf", gc(xdtoa(tinymath_round(-INFINITY)))); } TEST(lround, test) { @@ -65,10 +65,10 @@ TEST(roundf, test) { TEST(roundf, testCornerCases) { EXPECT_STREQ("-0", gc(xdtoa(tinymath_roundf(-0.0)))); - EXPECT_STREQ("NAN", gc(xdtoa(tinymath_roundf(NAN)))); - EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_roundf(-NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_roundf(INFINITY)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_roundf(-INFINITY)))); + EXPECT_STREQ("nan", gc(xdtoa(tinymath_roundf(NAN)))); + EXPECT_STREQ("-nan", gc(xdtoa(tinymath_roundf(-NAN)))); + EXPECT_STREQ("inf", gc(xdtoa(tinymath_roundf(INFINITY)))); + EXPECT_STREQ("-inf", gc(xdtoa(tinymath_roundf(-INFINITY)))); } TEST(lroundf, test) { @@ -103,18 +103,18 @@ TEST(roundf$k8, test) { TEST(round$k8, testCornerCases) { EXPECT_STREQ("-0", gc(xdtoa(tinymath_round$k8(-0.0)))); - EXPECT_STREQ("NAN", gc(xdtoa(tinymath_round$k8(NAN)))); - EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_round$k8(-NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_round$k8(INFINITY)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_round$k8(-INFINITY)))); + EXPECT_STREQ("nan", gc(xdtoa(tinymath_round$k8(NAN)))); + EXPECT_STREQ("-nan", gc(xdtoa(tinymath_round$k8(-NAN)))); + EXPECT_STREQ("inf", gc(xdtoa(tinymath_round$k8(INFINITY)))); + EXPECT_STREQ("-inf", gc(xdtoa(tinymath_round$k8(-INFINITY)))); } TEST(roundf$k8, testCornerCases) { EXPECT_STREQ("-0", gc(xdtoa(tinymath_roundf$k8(-0.0)))); - EXPECT_STREQ("NAN", gc(xdtoa(tinymath_roundf$k8(NAN)))); - EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_roundf$k8(-NAN)))); - EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_roundf$k8(INFINITY)))); - EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_roundf$k8(-INFINITY)))); + EXPECT_STREQ("nan", gc(xdtoa(tinymath_roundf$k8(NAN)))); + EXPECT_STREQ("-nan", gc(xdtoa(tinymath_roundf$k8(-NAN)))); + EXPECT_STREQ("inf", gc(xdtoa(tinymath_roundf$k8(INFINITY)))); + EXPECT_STREQ("-inf", gc(xdtoa(tinymath_roundf$k8(-INFINITY)))); } #endif diff --git a/test/libc/unicode/wcwidth_test.c b/test/libc/unicode/wcwidth_test.c index bb357afe..b644c4fa 100644 --- a/test/libc/unicode/wcwidth_test.c +++ b/test/libc/unicode/wcwidth_test.c @@ -83,3 +83,8 @@ TEST(strwidth, tab) { TEST(wcwidth, block) { EXPECT_EQ(1, wcwidth(u'▄')); } + +TEST(strwidth, testTextDelimitingControlCodes_dontHaveSubstance) { + EXPECT_EQ(0, strwidth("\0")); + EXPECT_EQ(0, strwidth("\1")); +} diff --git a/third_party/compiler_rt/compiler_rt.mk b/third_party/compiler_rt/compiler_rt.mk index 9b8a9089..33f16292 100644 --- a/third_party/compiler_rt/compiler_rt.mk +++ b/third_party/compiler_rt/compiler_rt.mk @@ -27,7 +27,7 @@ THIRD_PARTY_COMPILER_RT_A_CHECKS = \ $(THIRD_PARTY_COMPILER_RT_A_HDRS:%=o/$(MODE)/%.ok) THIRD_PARTY_COMPILER_RT_A_DIRECTDEPS = \ - LIBC_MATH \ + LIBC_TINYMATH \ LIBC_STUBS THIRD_PARTY_COMPILER_RT_A_DEPS := \ diff --git a/third_party/dlmalloc/dlmalloc.c b/third_party/dlmalloc/dlmalloc.c index 700d62b8..7a8deec5 100644 --- a/third_party/dlmalloc/dlmalloc.c +++ b/third_party/dlmalloc/dlmalloc.c @@ -1029,5 +1029,3 @@ void *dlrealloc(void *oldmem, size_t bytes) { } return mem; } - -asm(".include \"third_party/dlmalloc/COPYING\""); diff --git a/third_party/dtoa/dtoa.c b/third_party/dtoa/dtoa.c index 9fda286f..107c02b6 100644 --- a/third_party/dtoa/dtoa.c +++ b/third_party/dtoa/dtoa.c @@ -22,7 +22,6 @@ The author of this software is David M. Gay.\\n\ Copyright (c) 1991, 2000, 2001 by Lucent Technologies.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ /**************************************************************** * * The author of this software is David M. Gay. @@ -172,7 +171,7 @@ asm(".include \"libc/disclaimer.inc\""); * multiple threads. In this case, you must provide (or suitably * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed - * in pow5mult, ensures lazy evaluation of only one copy of high + * in dtoa_pow5mult, ensures lazy evaluation of only one copy of high * powers of 5; omitting this lock would introduce a small * probability of wasting memory, but would otherwise be harmless.) * You must also invoke freedtoa(s) to free the value s returned by @@ -243,12 +242,18 @@ typedef unsigned Long ULong; #ifdef DEBUG #include "libc/assert.h" -#define Bug(x) {dprintf(STDERR_FILENO, "%s\n", x); exit(1);} +#define Bug(x) \ + { \ + dprintf(STDERR_FILENO, "%s\n", x); \ + exit(1); \ + } #define Debug(x) x -int dtoa_stats[7]; /* strtod_{64,96,bigcomp},dtoa_{exact,64,96,bigcomp} */ +int dtoa_stats + [7]; /* strtod_{64,96,dtoa_bigcomp},dtoa_{exact,64,96,dtoa_bigcomp} + */ #else #define assert(x) /*nothing*/ -#define Debug(x) /*nothing*/ +#define Debug(x) /*nothing*/ #endif #include "libc/mem/mem.h" @@ -271,7 +276,7 @@ extern void *MALLOC(size_t); #endif #ifdef REALLOC -extern void *REALLOC(void*,size_t); +extern void *REALLOC(void *, size_t); #else #define REALLOC realloc #endif @@ -281,16 +286,16 @@ extern void *REALLOC(void*,size_t); #endif #ifdef __cplusplus - } +} #endif #ifndef Omit_Private_Memory #ifndef PRIVATE_MEM #define PRIVATE_MEM 2304 #endif -#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double)) +#define PRIVATE_mem ((PRIVATE_MEM + sizeof(double) - 1) / sizeof(double)) static double private_mem[PRIVATE_mem], *pmem_next; -INITIALIZER(300, _init_dtoa_pmem, {pmem_next = private_mem;}); +INITIALIZER(300, _init_dtoa_pmem, { pmem_next = private_mem; }); #endif #undef IEEE_Arith @@ -326,26 +331,26 @@ INITIALIZER(300, _init_dtoa_pmem, {pmem_next = private_mem;}); #ifdef Bad_float_h #ifdef IEEE_Arith -#define DBL_DIG 15 +#define DBL_DIG 15 #define DBL_MAX_10_EXP 308 -#define DBL_MAX_EXP 1024 -#define FLT_RADIX 2 +#define DBL_MAX_EXP 1024 +#define FLT_RADIX 2 #endif /*IEEE_Arith*/ #ifdef IBM -#define DBL_DIG 16 +#define DBL_DIG 16 #define DBL_MAX_10_EXP 75 -#define DBL_MAX_EXP 63 -#define FLT_RADIX 16 -#define DBL_MAX 7.2370055773322621e+75 +#define DBL_MAX_EXP 63 +#define FLT_RADIX 16 +#define DBL_MAX 7.2370055773322621e+75 #endif #ifdef VAX -#define DBL_DIG 16 +#define DBL_DIG 16 #define DBL_MAX_10_EXP 38 -#define DBL_MAX_EXP 127 -#define FLT_RADIX 2 -#define DBL_MAX 1.7014118346046923e+38 +#define DBL_MAX_EXP 127 +#define FLT_RADIX 2 +#define DBL_MAX 1.7014118346046923e+38 #endif #ifndef LONG_MAX @@ -380,7 +385,7 @@ Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. * slower. Hence the default is now to store 32 bits per Long. */ #endif -#else /*}{ long long available */ +#else /*}{ long long available */ #ifndef Llong #define Llong long long #endif @@ -393,938 +398,903 @@ Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. #ifdef SET_INEXACT #define dtoa_divmax 27 #else -int dtoa_divmax; /* Permit experimenting: on some systems, 64-bit integer */ - /* division is slow enough that we may sometimes want to */ - /* avoid using it. We assume (but do not check) that */ - /* dtoa_divmax <= 27.*/ -INITIALIZER(300, _init_dtoa_divmax, {dtoa_divmax = 2;}); +int dtoa_divmax; /* Permit experimenting: on some systems, 64-bit integer */ + /* division is slow enough that we may sometimes want to */ + /* avoid using it. We assume (but do not check) that */ + /* dtoa_divmax <= 27.*/ +INITIALIZER(300, _init_dtoa_divmax, { dtoa_divmax = 2; }); #endif -typedef struct BF96 { /* Normalized 96-bit software floating point numbers */ - unsigned int b0,b1,b2; /* b0 = most significant, binary point just to its left */ - int e; /* number represented = b * 2^e, with .5 <= b < 1 */ - } BF96; +typedef struct BF96 { /* Normalized 96-bit software floating point numbers */ + unsigned int b0, b1, + b2; /* b0 = most significant, binary point just to its left */ + int e; /* number represented = b * 2^e, with .5 <= b < 1 */ +} BF96; - static const BF96 pten[667] = { - { 0xeef453d6, 0x923bd65a, 0x113faa29, -1136 }, - { 0x9558b466, 0x1b6565f8, 0x4ac7ca59, -1132 }, - { 0xbaaee17f, 0xa23ebf76, 0x5d79bcf0, -1129 }, - { 0xe95a99df, 0x8ace6f53, 0xf4d82c2c, -1126 }, - { 0x91d8a02b, 0xb6c10594, 0x79071b9b, -1122 }, - { 0xb64ec836, 0xa47146f9, 0x9748e282, -1119 }, - { 0xe3e27a44, 0x4d8d98b7, 0xfd1b1b23, -1116 }, - { 0x8e6d8c6a, 0xb0787f72, 0xfe30f0f5, -1112 }, - { 0xb208ef85, 0x5c969f4f, 0xbdbd2d33, -1109 }, - { 0xde8b2b66, 0xb3bc4723, 0xad2c7880, -1106 }, - { 0x8b16fb20, 0x3055ac76, 0x4c3bcb50, -1102 }, - { 0xaddcb9e8, 0x3c6b1793, 0xdf4abe24, -1099 }, - { 0xd953e862, 0x4b85dd78, 0xd71d6dad, -1096 }, - { 0x87d4713d, 0x6f33aa6b, 0x8672648c, -1092 }, - { 0xa9c98d8c, 0xcb009506, 0x680efdaf, -1089 }, - { 0xd43bf0ef, 0xfdc0ba48, 0x0212bd1b, -1086 }, - { 0x84a57695, 0xfe98746d, 0x014bb630, -1082 }, - { 0xa5ced43b, 0x7e3e9188, 0x419ea3bd, -1079 }, - { 0xcf42894a, 0x5dce35ea, 0x52064cac, -1076 }, - { 0x818995ce, 0x7aa0e1b2, 0x7343efeb, -1072 }, - { 0xa1ebfb42, 0x19491a1f, 0x1014ebe6, -1069 }, - { 0xca66fa12, 0x9f9b60a6, 0xd41a26e0, -1066 }, - { 0xfd00b897, 0x478238d0, 0x8920b098, -1063 }, - { 0x9e20735e, 0x8cb16382, 0x55b46e5f, -1059 }, - { 0xc5a89036, 0x2fddbc62, 0xeb2189f7, -1056 }, - { 0xf712b443, 0xbbd52b7b, 0xa5e9ec75, -1053 }, - { 0x9a6bb0aa, 0x55653b2d, 0x47b233c9, -1049 }, - { 0xc1069cd4, 0xeabe89f8, 0x999ec0bb, -1046 }, - { 0xf148440a, 0x256e2c76, 0xc00670ea, -1043 }, - { 0x96cd2a86, 0x5764dbca, 0x38040692, -1039 }, - { 0xbc807527, 0xed3e12bc, 0xc6050837, -1036 }, - { 0xeba09271, 0xe88d976b, 0xf7864a44, -1033 }, - { 0x93445b87, 0x31587ea3, 0x7ab3ee6a, -1029 }, - { 0xb8157268, 0xfdae9e4c, 0x5960ea05, -1026 }, - { 0xe61acf03, 0x3d1a45df, 0x6fb92487, -1023 }, - { 0x8fd0c162, 0x06306bab, 0xa5d3b6d4, -1019 }, - { 0xb3c4f1ba, 0x87bc8696, 0x8f48a489, -1016 }, - { 0xe0b62e29, 0x29aba83c, 0x331acdab, -1013 }, - { 0x8c71dcd9, 0xba0b4925, 0x9ff0c08b, -1009 }, - { 0xaf8e5410, 0x288e1b6f, 0x07ecf0ae, -1006 }, - { 0xdb71e914, 0x32b1a24a, 0xc9e82cd9, -1003 }, - { 0x892731ac, 0x9faf056e, 0xbe311c08, -999 }, - { 0xab70fe17, 0xc79ac6ca, 0x6dbd630a, -996 }, - { 0xd64d3d9d, 0xb981787d, 0x092cbbcc, -993 }, - { 0x85f04682, 0x93f0eb4e, 0x25bbf560, -989 }, - { 0xa76c5823, 0x38ed2621, 0xaf2af2b8, -986 }, - { 0xd1476e2c, 0x07286faa, 0x1af5af66, -983 }, - { 0x82cca4db, 0x847945ca, 0x50d98d9f, -979 }, - { 0xa37fce12, 0x6597973c, 0xe50ff107, -976 }, - { 0xcc5fc196, 0xfefd7d0c, 0x1e53ed49, -973 }, - { 0xff77b1fc, 0xbebcdc4f, 0x25e8e89c, -970 }, - { 0x9faacf3d, 0xf73609b1, 0x77b19161, -966 }, - { 0xc795830d, 0x75038c1d, 0xd59df5b9, -963 }, - { 0xf97ae3d0, 0xd2446f25, 0x4b057328, -960 }, - { 0x9becce62, 0x836ac577, 0x4ee367f9, -956 }, - { 0xc2e801fb, 0x244576d5, 0x229c41f7, -953 }, - { 0xf3a20279, 0xed56d48a, 0x6b435275, -950 }, - { 0x9845418c, 0x345644d6, 0x830a1389, -946 }, - { 0xbe5691ef, 0x416bd60c, 0x23cc986b, -943 }, - { 0xedec366b, 0x11c6cb8f, 0x2cbfbe86, -940 }, - { 0x94b3a202, 0xeb1c3f39, 0x7bf7d714, -936 }, - { 0xb9e08a83, 0xa5e34f07, 0xdaf5ccd9, -933 }, - { 0xe858ad24, 0x8f5c22c9, 0xd1b3400f, -930 }, - { 0x91376c36, 0xd99995be, 0x23100809, -926 }, - { 0xb5854744, 0x8ffffb2d, 0xabd40a0c, -923 }, - { 0xe2e69915, 0xb3fff9f9, 0x16c90c8f, -920 }, - { 0x8dd01fad, 0x907ffc3b, 0xae3da7d9, -916 }, - { 0xb1442798, 0xf49ffb4a, 0x99cd11cf, -913 }, - { 0xdd95317f, 0x31c7fa1d, 0x40405643, -910 }, - { 0x8a7d3eef, 0x7f1cfc52, 0x482835ea, -906 }, - { 0xad1c8eab, 0x5ee43b66, 0xda324365, -903 }, - { 0xd863b256, 0x369d4a40, 0x90bed43e, -900 }, - { 0x873e4f75, 0xe2224e68, 0x5a7744a6, -896 }, - { 0xa90de353, 0x5aaae202, 0x711515d0, -893 }, - { 0xd3515c28, 0x31559a83, 0x0d5a5b44, -890 }, - { 0x8412d999, 0x1ed58091, 0xe858790a, -886 }, - { 0xa5178fff, 0x668ae0b6, 0x626e974d, -883 }, - { 0xce5d73ff, 0x402d98e3, 0xfb0a3d21, -880 }, - { 0x80fa687f, 0x881c7f8e, 0x7ce66634, -876 }, - { 0xa139029f, 0x6a239f72, 0x1c1fffc1, -873 }, - { 0xc9874347, 0x44ac874e, 0xa327ffb2, -870 }, - { 0xfbe91419, 0x15d7a922, 0x4bf1ff9f, -867 }, - { 0x9d71ac8f, 0xada6c9b5, 0x6f773fc3, -863 }, - { 0xc4ce17b3, 0x99107c22, 0xcb550fb4, -860 }, - { 0xf6019da0, 0x7f549b2b, 0x7e2a53a1, -857 }, - { 0x99c10284, 0x4f94e0fb, 0x2eda7444, -853 }, - { 0xc0314325, 0x637a1939, 0xfa911155, -850 }, - { 0xf03d93ee, 0xbc589f88, 0x793555ab, -847 }, - { 0x96267c75, 0x35b763b5, 0x4bc1558b, -843 }, - { 0xbbb01b92, 0x83253ca2, 0x9eb1aaed, -840 }, - { 0xea9c2277, 0x23ee8bcb, 0x465e15a9, -837 }, - { 0x92a1958a, 0x7675175f, 0x0bfacd89, -833 }, - { 0xb749faed, 0x14125d36, 0xcef980ec, -830 }, - { 0xe51c79a8, 0x5916f484, 0x82b7e127, -827 }, - { 0x8f31cc09, 0x37ae58d2, 0xd1b2ecb8, -823 }, - { 0xb2fe3f0b, 0x8599ef07, 0x861fa7e6, -820 }, - { 0xdfbdcece, 0x67006ac9, 0x67a791e0, -817 }, - { 0x8bd6a141, 0x006042bd, 0xe0c8bb2c, -813 }, - { 0xaecc4991, 0x4078536d, 0x58fae9f7, -810 }, - { 0xda7f5bf5, 0x90966848, 0xaf39a475, -807 }, - { 0x888f9979, 0x7a5e012d, 0x6d8406c9, -803 }, - { 0xaab37fd7, 0xd8f58178, 0xc8e5087b, -800 }, - { 0xd5605fcd, 0xcf32e1d6, 0xfb1e4a9a, -797 }, - { 0x855c3be0, 0xa17fcd26, 0x5cf2eea0, -793 }, - { 0xa6b34ad8, 0xc9dfc06f, 0xf42faa48, -790 }, - { 0xd0601d8e, 0xfc57b08b, 0xf13b94da, -787 }, - { 0x823c1279, 0x5db6ce57, 0x76c53d08, -783 }, - { 0xa2cb1717, 0xb52481ed, 0x54768c4b, -780 }, - { 0xcb7ddcdd, 0xa26da268, 0xa9942f5d, -777 }, - { 0xfe5d5415, 0x0b090b02, 0xd3f93b35, -774 }, - { 0x9efa548d, 0x26e5a6e1, 0xc47bc501, -770 }, - { 0xc6b8e9b0, 0x709f109a, 0x359ab641, -767 }, - { 0xf867241c, 0x8cc6d4c0, 0xc30163d2, -764 }, - { 0x9b407691, 0xd7fc44f8, 0x79e0de63, -760 }, - { 0xc2109436, 0x4dfb5636, 0x985915fc, -757 }, - { 0xf294b943, 0xe17a2bc4, 0x3e6f5b7b, -754 }, - { 0x979cf3ca, 0x6cec5b5a, 0xa705992c, -750 }, - { 0xbd8430bd, 0x08277231, 0x50c6ff78, -747 }, - { 0xece53cec, 0x4a314ebd, 0xa4f8bf56, -744 }, - { 0x940f4613, 0xae5ed136, 0x871b7795, -740 }, - { 0xb9131798, 0x99f68584, 0x28e2557b, -737 }, - { 0xe757dd7e, 0xc07426e5, 0x331aeada, -734 }, - { 0x9096ea6f, 0x3848984f, 0x3ff0d2c8, -730 }, - { 0xb4bca50b, 0x065abe63, 0x0fed077a, -727 }, - { 0xe1ebce4d, 0xc7f16dfb, 0xd3e84959, -724 }, - { 0x8d3360f0, 0x9cf6e4bd, 0x64712dd7, -720 }, - { 0xb080392c, 0xc4349dec, 0xbd8d794d, -717 }, - { 0xdca04777, 0xf541c567, 0xecf0d7a0, -714 }, - { 0x89e42caa, 0xf9491b60, 0xf41686c4, -710 }, - { 0xac5d37d5, 0xb79b6239, 0x311c2875, -707 }, - { 0xd77485cb, 0x25823ac7, 0x7d633293, -704 }, - { 0x86a8d39e, 0xf77164bc, 0xae5dff9c, -700 }, - { 0xa8530886, 0xb54dbdeb, 0xd9f57f83, -697 }, - { 0xd267caa8, 0x62a12d66, 0xd072df63, -694 }, - { 0x8380dea9, 0x3da4bc60, 0x4247cb9e, -690 }, - { 0xa4611653, 0x8d0deb78, 0x52d9be85, -687 }, - { 0xcd795be8, 0x70516656, 0x67902e27, -684 }, - { 0x806bd971, 0x4632dff6, 0x00ba1cd8, -680 }, - { 0xa086cfcd, 0x97bf97f3, 0x80e8a40e, -677 }, - { 0xc8a883c0, 0xfdaf7df0, 0x6122cd12, -674 }, - { 0xfad2a4b1, 0x3d1b5d6c, 0x796b8057, -671 }, - { 0x9cc3a6ee, 0xc6311a63, 0xcbe33036, -667 }, - { 0xc3f490aa, 0x77bd60fc, 0xbedbfc44, -664 }, - { 0xf4f1b4d5, 0x15acb93b, 0xee92fb55, -661 }, - { 0x99171105, 0x2d8bf3c5, 0x751bdd15, -657 }, - { 0xbf5cd546, 0x78eef0b6, 0xd262d45a, -654 }, - { 0xef340a98, 0x172aace4, 0x86fb8971, -651 }, - { 0x9580869f, 0x0e7aac0e, 0xd45d35e6, -647 }, - { 0xbae0a846, 0xd2195712, 0x89748360, -644 }, - { 0xe998d258, 0x869facd7, 0x2bd1a438, -641 }, - { 0x91ff8377, 0x5423cc06, 0x7b6306a3, -637 }, - { 0xb67f6455, 0x292cbf08, 0x1a3bc84c, -634 }, - { 0xe41f3d6a, 0x7377eeca, 0x20caba5f, -631 }, - { 0x8e938662, 0x882af53e, 0x547eb47b, -627 }, - { 0xb23867fb, 0x2a35b28d, 0xe99e619a, -624 }, - { 0xdec681f9, 0xf4c31f31, 0x6405fa00, -621 }, - { 0x8b3c113c, 0x38f9f37e, 0xde83bc40, -617 }, - { 0xae0b158b, 0x4738705e, 0x9624ab50, -614 }, - { 0xd98ddaee, 0x19068c76, 0x3badd624, -611 }, - { 0x87f8a8d4, 0xcfa417c9, 0xe54ca5d7, -607 }, - { 0xa9f6d30a, 0x038d1dbc, 0x5e9fcf4c, -604 }, - { 0xd47487cc, 0x8470652b, 0x7647c320, -601 }, - { 0x84c8d4df, 0xd2c63f3b, 0x29ecd9f4, -597 }, - { 0xa5fb0a17, 0xc777cf09, 0xf4681071, -594 }, - { 0xcf79cc9d, 0xb955c2cc, 0x7182148d, -591 }, - { 0x81ac1fe2, 0x93d599bf, 0xc6f14cd8, -587 }, - { 0xa21727db, 0x38cb002f, 0xb8ada00e, -584 }, - { 0xca9cf1d2, 0x06fdc03b, 0xa6d90811, -581 }, - { 0xfd442e46, 0x88bd304a, 0x908f4a16, -578 }, - { 0x9e4a9cec, 0x15763e2e, 0x9a598e4e, -574 }, - { 0xc5dd4427, 0x1ad3cdba, 0x40eff1e1, -571 }, - { 0xf7549530, 0xe188c128, 0xd12bee59, -568 }, - { 0x9a94dd3e, 0x8cf578b9, 0x82bb74f8, -564 }, - { 0xc13a148e, 0x3032d6e7, 0xe36a5236, -561 }, - { 0xf18899b1, 0xbc3f8ca1, 0xdc44e6c3, -558 }, - { 0x96f5600f, 0x15a7b7e5, 0x29ab103a, -554 }, - { 0xbcb2b812, 0xdb11a5de, 0x7415d448, -551 }, - { 0xebdf6617, 0x91d60f56, 0x111b495b, -548 }, - { 0x936b9fce, 0xbb25c995, 0xcab10dd9, -544 }, - { 0xb84687c2, 0x69ef3bfb, 0x3d5d514f, -541 }, - { 0xe65829b3, 0x046b0afa, 0x0cb4a5a3, -538 }, - { 0x8ff71a0f, 0xe2c2e6dc, 0x47f0e785, -534 }, - { 0xb3f4e093, 0xdb73a093, 0x59ed2167, -531 }, - { 0xe0f218b8, 0xd25088b8, 0x306869c1, -528 }, - { 0x8c974f73, 0x83725573, 0x1e414218, -524 }, - { 0xafbd2350, 0x644eeacf, 0xe5d1929e, -521 }, - { 0xdbac6c24, 0x7d62a583, 0xdf45f746, -518 }, - { 0x894bc396, 0xce5da772, 0x6b8bba8c, -514 }, - { 0xab9eb47c, 0x81f5114f, 0x066ea92f, -511 }, - { 0xd686619b, 0xa27255a2, 0xc80a537b, -508 }, - { 0x8613fd01, 0x45877585, 0xbd06742c, -504 }, - { 0xa798fc41, 0x96e952e7, 0x2c481138, -501 }, - { 0xd17f3b51, 0xfca3a7a0, 0xf75a1586, -498 }, - { 0x82ef8513, 0x3de648c4, 0x9a984d73, -494 }, - { 0xa3ab6658, 0x0d5fdaf5, 0xc13e60d0, -491 }, - { 0xcc963fee, 0x10b7d1b3, 0x318df905, -488 }, - { 0xffbbcfe9, 0x94e5c61f, 0xfdf17746, -485 }, - { 0x9fd561f1, 0xfd0f9bd3, 0xfeb6ea8b, -481 }, - { 0xc7caba6e, 0x7c5382c8, 0xfe64a52e, -478 }, - { 0xf9bd690a, 0x1b68637b, 0x3dfdce7a, -475 }, - { 0x9c1661a6, 0x51213e2d, 0x06bea10c, -471 }, - { 0xc31bfa0f, 0xe5698db8, 0x486e494f, -468 }, - { 0xf3e2f893, 0xdec3f126, 0x5a89dba3, -465 }, - { 0x986ddb5c, 0x6b3a76b7, 0xf8962946, -461 }, - { 0xbe895233, 0x86091465, 0xf6bbb397, -458 }, - { 0xee2ba6c0, 0x678b597f, 0x746aa07d, -455 }, - { 0x94db4838, 0x40b717ef, 0xa8c2a44e, -451 }, - { 0xba121a46, 0x50e4ddeb, 0x92f34d62, -448 }, - { 0xe896a0d7, 0xe51e1566, 0x77b020ba, -445 }, - { 0x915e2486, 0xef32cd60, 0x0ace1474, -441 }, - { 0xb5b5ada8, 0xaaff80b8, 0x0d819992, -438 }, - { 0xe3231912, 0xd5bf60e6, 0x10e1fff6, -435 }, - { 0x8df5efab, 0xc5979c8f, 0xca8d3ffa, -431 }, - { 0xb1736b96, 0xb6fd83b3, 0xbd308ff8, -428 }, - { 0xddd0467c, 0x64bce4a0, 0xac7cb3f6, -425 }, - { 0x8aa22c0d, 0xbef60ee4, 0x6bcdf07a, -421 }, - { 0xad4ab711, 0x2eb3929d, 0x86c16c98, -418 }, - { 0xd89d64d5, 0x7a607744, 0xe871c7bf, -415 }, - { 0x87625f05, 0x6c7c4a8b, 0x11471cd7, -411 }, - { 0xa93af6c6, 0xc79b5d2d, 0xd598e40d, -408 }, - { 0xd389b478, 0x79823479, 0x4aff1d10, -405 }, - { 0x843610cb, 0x4bf160cb, 0xcedf722a, -401 }, - { 0xa54394fe, 0x1eedb8fe, 0xc2974eb4, -398 }, - { 0xce947a3d, 0xa6a9273e, 0x733d2262, -395 }, - { 0x811ccc66, 0x8829b887, 0x0806357d, -391 }, - { 0xa163ff80, 0x2a3426a8, 0xca07c2dc, -388 }, - { 0xc9bcff60, 0x34c13052, 0xfc89b393, -385 }, - { 0xfc2c3f38, 0x41f17c67, 0xbbac2078, -382 }, - { 0x9d9ba783, 0x2936edc0, 0xd54b944b, -378 }, - { 0xc5029163, 0xf384a931, 0x0a9e795e, -375 }, - { 0xf64335bc, 0xf065d37d, 0x4d4617b5, -372 }, - { 0x99ea0196, 0x163fa42e, 0x504bced1, -368 }, - { 0xc06481fb, 0x9bcf8d39, 0xe45ec286, -365 }, - { 0xf07da27a, 0x82c37088, 0x5d767327, -362 }, - { 0x964e858c, 0x91ba2655, 0x3a6a07f8, -358 }, - { 0xbbe226ef, 0xb628afea, 0x890489f7, -355 }, - { 0xeadab0ab, 0xa3b2dbe5, 0x2b45ac74, -352 }, - { 0x92c8ae6b, 0x464fc96f, 0x3b0b8bc9, -348 }, - { 0xb77ada06, 0x17e3bbcb, 0x09ce6ebb, -345 }, - { 0xe5599087, 0x9ddcaabd, 0xcc420a6a, -342 }, - { 0x8f57fa54, 0xc2a9eab6, 0x9fa94682, -338 }, - { 0xb32df8e9, 0xf3546564, 0x47939822, -335 }, - { 0xdff97724, 0x70297ebd, 0x59787e2b, -332 }, - { 0x8bfbea76, 0xc619ef36, 0x57eb4edb, -328 }, - { 0xaefae514, 0x77a06b03, 0xede62292, -325 }, - { 0xdab99e59, 0x958885c4, 0xe95fab36, -322 }, - { 0x88b402f7, 0xfd75539b, 0x11dbcb02, -318 }, - { 0xaae103b5, 0xfcd2a881, 0xd652bdc2, -315 }, - { 0xd59944a3, 0x7c0752a2, 0x4be76d33, -312 }, - { 0x857fcae6, 0x2d8493a5, 0x6f70a440, -308 }, - { 0xa6dfbd9f, 0xb8e5b88e, 0xcb4ccd50, -305 }, - { 0xd097ad07, 0xa71f26b2, 0x7e2000a4, -302 }, - { 0x825ecc24, 0xc873782f, 0x8ed40066, -298 }, - { 0xa2f67f2d, 0xfa90563b, 0x72890080, -295 }, - { 0xcbb41ef9, 0x79346bca, 0x4f2b40a0, -292 }, - { 0xfea126b7, 0xd78186bc, 0xe2f610c8, -289 }, - { 0x9f24b832, 0xe6b0f436, 0x0dd9ca7d, -285 }, - { 0xc6ede63f, 0xa05d3143, 0x91503d1c, -282 }, - { 0xf8a95fcf, 0x88747d94, 0x75a44c63, -279 }, - { 0x9b69dbe1, 0xb548ce7c, 0xc986afbe, -275 }, - { 0xc24452da, 0x229b021b, 0xfbe85bad, -272 }, - { 0xf2d56790, 0xab41c2a2, 0xfae27299, -269 }, - { 0x97c560ba, 0x6b0919a5, 0xdccd879f, -265 }, - { 0xbdb6b8e9, 0x05cb600f, 0x5400e987, -262 }, - { 0xed246723, 0x473e3813, 0x290123e9, -259 }, - { 0x9436c076, 0x0c86e30b, 0xf9a0b672, -255 }, - { 0xb9447093, 0x8fa89bce, 0xf808e40e, -252 }, - { 0xe7958cb8, 0x7392c2c2, 0xb60b1d12, -249 }, - { 0x90bd77f3, 0x483bb9b9, 0xb1c6f22b, -245 }, - { 0xb4ecd5f0, 0x1a4aa828, 0x1e38aeb6, -242 }, - { 0xe2280b6c, 0x20dd5232, 0x25c6da63, -239 }, - { 0x8d590723, 0x948a535f, 0x579c487e, -235 }, - { 0xb0af48ec, 0x79ace837, 0x2d835a9d, -232 }, - { 0xdcdb1b27, 0x98182244, 0xf8e43145, -229 }, - { 0x8a08f0f8, 0xbf0f156b, 0x1b8e9ecb, -225 }, - { 0xac8b2d36, 0xeed2dac5, 0xe272467e, -222 }, - { 0xd7adf884, 0xaa879177, 0x5b0ed81d, -219 }, - { 0x86ccbb52, 0xea94baea, 0x98e94712, -215 }, - { 0xa87fea27, 0xa539e9a5, 0x3f2398d7, -212 }, - { 0xd29fe4b1, 0x8e88640e, 0x8eec7f0d, -209 }, - { 0x83a3eeee, 0xf9153e89, 0x1953cf68, -205 }, - { 0xa48ceaaa, 0xb75a8e2b, 0x5fa8c342, -202 }, - { 0xcdb02555, 0x653131b6, 0x3792f412, -199 }, - { 0x808e1755, 0x5f3ebf11, 0xe2bbd88b, -195 }, - { 0xa0b19d2a, 0xb70e6ed6, 0x5b6aceae, -192 }, - { 0xc8de0475, 0x64d20a8b, 0xf245825a, -189 }, - { 0xfb158592, 0xbe068d2e, 0xeed6e2f0, -186 }, - { 0x9ced737b, 0xb6c4183d, 0x55464dd6, -182 }, - { 0xc428d05a, 0xa4751e4c, 0xaa97e14c, -179 }, - { 0xf5330471, 0x4d9265df, 0xd53dd99f, -176 }, - { 0x993fe2c6, 0xd07b7fab, 0xe546a803, -172 }, - { 0xbf8fdb78, 0x849a5f96, 0xde985204, -169 }, - { 0xef73d256, 0xa5c0f77c, 0x963e6685, -166 }, - { 0x95a86376, 0x27989aad, 0xdde70013, -162 }, - { 0xbb127c53, 0xb17ec159, 0x5560c018, -159 }, - { 0xe9d71b68, 0x9dde71af, 0xaab8f01e, -156 }, - { 0x92267121, 0x62ab070d, 0xcab39613, -152 }, - { 0xb6b00d69, 0xbb55c8d1, 0x3d607b97, -149 }, - { 0xe45c10c4, 0x2a2b3b05, 0x8cb89a7d, -146 }, - { 0x8eb98a7a, 0x9a5b04e3, 0x77f3608e, -142 }, - { 0xb267ed19, 0x40f1c61c, 0x55f038b2, -139 }, - { 0xdf01e85f, 0x912e37a3, 0x6b6c46de, -136 }, - { 0x8b61313b, 0xbabce2c6, 0x2323ac4b, -132 }, - { 0xae397d8a, 0xa96c1b77, 0xabec975e, -129 }, - { 0xd9c7dced, 0x53c72255, 0x96e7bd35, -126 }, - { 0x881cea14, 0x545c7575, 0x7e50d641, -122 }, - { 0xaa242499, 0x697392d2, 0xdde50bd1, -119 }, - { 0xd4ad2dbf, 0xc3d07787, 0x955e4ec6, -116 }, - { 0x84ec3c97, 0xda624ab4, 0xbd5af13b, -112 }, - { 0xa6274bbd, 0xd0fadd61, 0xecb1ad8a, -109 }, - { 0xcfb11ead, 0x453994ba, 0x67de18ed, -106 }, - { 0x81ceb32c, 0x4b43fcf4, 0x80eacf94, -102 }, - { 0xa2425ff7, 0x5e14fc31, 0xa1258379, -99 }, - { 0xcad2f7f5, 0x359a3b3e, 0x096ee458, -96 }, - { 0xfd87b5f2, 0x8300ca0d, 0x8bca9d6e, -93 }, - { 0x9e74d1b7, 0x91e07e48, 0x775ea264, -89 }, - { 0xc6120625, 0x76589dda, 0x95364afe, -86 }, - { 0xf79687ae, 0xd3eec551, 0x3a83ddbd, -83 }, - { 0x9abe14cd, 0x44753b52, 0xc4926a96, -79 }, - { 0xc16d9a00, 0x95928a27, 0x75b7053c, -76 }, - { 0xf1c90080, 0xbaf72cb1, 0x5324c68b, -73 }, - { 0x971da050, 0x74da7bee, 0xd3f6fc16, -69 }, - { 0xbce50864, 0x92111aea, 0x88f4bb1c, -66 }, - { 0xec1e4a7d, 0xb69561a5, 0x2b31e9e3, -63 }, - { 0x9392ee8e, 0x921d5d07, 0x3aff322e, -59 }, - { 0xb877aa32, 0x36a4b449, 0x09befeb9, -56 }, - { 0xe69594be, 0xc44de15b, 0x4c2ebe68, -53 }, - { 0x901d7cf7, 0x3ab0acd9, 0x0f9d3701, -49 }, - { 0xb424dc35, 0x095cd80f, 0x538484c1, -46 }, - { 0xe12e1342, 0x4bb40e13, 0x2865a5f2, -43 }, - { 0x8cbccc09, 0x6f5088cb, 0xf93f87b7, -39 }, - { 0xafebff0b, 0xcb24aafe, 0xf78f69a5, -36 }, - { 0xdbe6fece, 0xbdedd5be, 0xb573440e, -33 }, - { 0x89705f41, 0x36b4a597, 0x31680a88, -29 }, - { 0xabcc7711, 0x8461cefc, 0xfdc20d2b, -26 }, - { 0xd6bf94d5, 0xe57a42bc, 0x3d329076, -23 }, - { 0x8637bd05, 0xaf6c69b5, 0xa63f9a49, -19 }, - { 0xa7c5ac47, 0x1b478423, 0x0fcf80dc, -16 }, - { 0xd1b71758, 0xe219652b, 0xd3c36113, -13 }, - { 0x83126e97, 0x8d4fdf3b, 0x645a1cac, -9 }, - { 0xa3d70a3d, 0x70a3d70a, 0x3d70a3d7, -6 }, - { 0xcccccccc, 0xcccccccc, 0xcccccccc, -3 }, - { 0x80000000, 0x00000000, 0x00000000, 1 }, - { 0xa0000000, 0x00000000, 0x00000000, 4 }, - { 0xc8000000, 0x00000000, 0x00000000, 7 }, - { 0xfa000000, 0x00000000, 0x00000000, 10 }, - { 0x9c400000, 0x00000000, 0x00000000, 14 }, - { 0xc3500000, 0x00000000, 0x00000000, 17 }, - { 0xf4240000, 0x00000000, 0x00000000, 20 }, - { 0x98968000, 0x00000000, 0x00000000, 24 }, - { 0xbebc2000, 0x00000000, 0x00000000, 27 }, - { 0xee6b2800, 0x00000000, 0x00000000, 30 }, - { 0x9502f900, 0x00000000, 0x00000000, 34 }, - { 0xba43b740, 0x00000000, 0x00000000, 37 }, - { 0xe8d4a510, 0x00000000, 0x00000000, 40 }, - { 0x9184e72a, 0x00000000, 0x00000000, 44 }, - { 0xb5e620f4, 0x80000000, 0x00000000, 47 }, - { 0xe35fa931, 0xa0000000, 0x00000000, 50 }, - { 0x8e1bc9bf, 0x04000000, 0x00000000, 54 }, - { 0xb1a2bc2e, 0xc5000000, 0x00000000, 57 }, - { 0xde0b6b3a, 0x76400000, 0x00000000, 60 }, - { 0x8ac72304, 0x89e80000, 0x00000000, 64 }, - { 0xad78ebc5, 0xac620000, 0x00000000, 67 }, - { 0xd8d726b7, 0x177a8000, 0x00000000, 70 }, - { 0x87867832, 0x6eac9000, 0x00000000, 74 }, - { 0xa968163f, 0x0a57b400, 0x00000000, 77 }, - { 0xd3c21bce, 0xcceda100, 0x00000000, 80 }, - { 0x84595161, 0x401484a0, 0x00000000, 84 }, - { 0xa56fa5b9, 0x9019a5c8, 0x00000000, 87 }, - { 0xcecb8f27, 0xf4200f3a, 0x00000000, 90 }, - { 0x813f3978, 0xf8940984, 0x40000000, 94 }, - { 0xa18f07d7, 0x36b90be5, 0x50000000, 97 }, - { 0xc9f2c9cd, 0x04674ede, 0xa4000000, 100 }, - { 0xfc6f7c40, 0x45812296, 0x4d000000, 103 }, - { 0x9dc5ada8, 0x2b70b59d, 0xf0200000, 107 }, - { 0xc5371912, 0x364ce305, 0x6c280000, 110 }, - { 0xf684df56, 0xc3e01bc6, 0xc7320000, 113 }, - { 0x9a130b96, 0x3a6c115c, 0x3c7f4000, 117 }, - { 0xc097ce7b, 0xc90715b3, 0x4b9f1000, 120 }, - { 0xf0bdc21a, 0xbb48db20, 0x1e86d400, 123 }, - { 0x96769950, 0xb50d88f4, 0x13144480, 127 }, - { 0xbc143fa4, 0xe250eb31, 0x17d955a0, 130 }, - { 0xeb194f8e, 0x1ae525fd, 0x5dcfab08, 133 }, - { 0x92efd1b8, 0xd0cf37be, 0x5aa1cae5, 137 }, - { 0xb7abc627, 0x050305ad, 0xf14a3d9e, 140 }, - { 0xe596b7b0, 0xc643c719, 0x6d9ccd05, 143 }, - { 0x8f7e32ce, 0x7bea5c6f, 0xe4820023, 147 }, - { 0xb35dbf82, 0x1ae4f38b, 0xdda2802c, 150 }, - { 0xe0352f62, 0xa19e306e, 0xd50b2037, 153 }, - { 0x8c213d9d, 0xa502de45, 0x4526f422, 157 }, - { 0xaf298d05, 0x0e4395d6, 0x9670b12b, 160 }, - { 0xdaf3f046, 0x51d47b4c, 0x3c0cdd76, 163 }, - { 0x88d8762b, 0xf324cd0f, 0xa5880a69, 167 }, - { 0xab0e93b6, 0xefee0053, 0x8eea0d04, 170 }, - { 0xd5d238a4, 0xabe98068, 0x72a49045, 173 }, - { 0x85a36366, 0xeb71f041, 0x47a6da2b, 177 }, - { 0xa70c3c40, 0xa64e6c51, 0x999090b6, 180 }, - { 0xd0cf4b50, 0xcfe20765, 0xfff4b4e3, 183 }, - { 0x82818f12, 0x81ed449f, 0xbff8f10e, 187 }, - { 0xa321f2d7, 0x226895c7, 0xaff72d52, 190 }, - { 0xcbea6f8c, 0xeb02bb39, 0x9bf4f8a6, 193 }, - { 0xfee50b70, 0x25c36a08, 0x02f236d0, 196 }, - { 0x9f4f2726, 0x179a2245, 0x01d76242, 200 }, - { 0xc722f0ef, 0x9d80aad6, 0x424d3ad2, 203 }, - { 0xf8ebad2b, 0x84e0d58b, 0xd2e08987, 206 }, - { 0x9b934c3b, 0x330c8577, 0x63cc55f4, 210 }, - { 0xc2781f49, 0xffcfa6d5, 0x3cbf6b71, 213 }, - { 0xf316271c, 0x7fc3908a, 0x8bef464e, 216 }, - { 0x97edd871, 0xcfda3a56, 0x97758bf0, 220 }, - { 0xbde94e8e, 0x43d0c8ec, 0x3d52eeed, 223 }, - { 0xed63a231, 0xd4c4fb27, 0x4ca7aaa8, 226 }, - { 0x945e455f, 0x24fb1cf8, 0x8fe8caa9, 230 }, - { 0xb975d6b6, 0xee39e436, 0xb3e2fd53, 233 }, - { 0xe7d34c64, 0xa9c85d44, 0x60dbbca8, 236 }, - { 0x90e40fbe, 0xea1d3a4a, 0xbc8955e9, 240 }, - { 0xb51d13ae, 0xa4a488dd, 0x6babab63, 243 }, - { 0xe264589a, 0x4dcdab14, 0xc696963c, 246 }, - { 0x8d7eb760, 0x70a08aec, 0xfc1e1de5, 250 }, - { 0xb0de6538, 0x8cc8ada8, 0x3b25a55f, 253 }, - { 0xdd15fe86, 0xaffad912, 0x49ef0eb7, 256 }, - { 0x8a2dbf14, 0x2dfcc7ab, 0x6e356932, 260 }, - { 0xacb92ed9, 0x397bf996, 0x49c2c37f, 263 }, - { 0xd7e77a8f, 0x87daf7fb, 0xdc33745e, 266 }, - { 0x86f0ac99, 0xb4e8dafd, 0x69a028bb, 270 }, - { 0xa8acd7c0, 0x222311bc, 0xc40832ea, 273 }, - { 0xd2d80db0, 0x2aabd62b, 0xf50a3fa4, 276 }, - { 0x83c7088e, 0x1aab65db, 0x792667c6, 280 }, - { 0xa4b8cab1, 0xa1563f52, 0x577001b8, 283 }, - { 0xcde6fd5e, 0x09abcf26, 0xed4c0226, 286 }, - { 0x80b05e5a, 0xc60b6178, 0x544f8158, 290 }, - { 0xa0dc75f1, 0x778e39d6, 0x696361ae, 293 }, - { 0xc913936d, 0xd571c84c, 0x03bc3a19, 296 }, - { 0xfb587849, 0x4ace3a5f, 0x04ab48a0, 299 }, - { 0x9d174b2d, 0xcec0e47b, 0x62eb0d64, 303 }, - { 0xc45d1df9, 0x42711d9a, 0x3ba5d0bd, 306 }, - { 0xf5746577, 0x930d6500, 0xca8f44ec, 309 }, - { 0x9968bf6a, 0xbbe85f20, 0x7e998b13, 313 }, - { 0xbfc2ef45, 0x6ae276e8, 0x9e3fedd8, 316 }, - { 0xefb3ab16, 0xc59b14a2, 0xc5cfe94e, 319 }, - { 0x95d04aee, 0x3b80ece5, 0xbba1f1d1, 323 }, - { 0xbb445da9, 0xca61281f, 0x2a8a6e45, 326 }, - { 0xea157514, 0x3cf97226, 0xf52d09d7, 329 }, - { 0x924d692c, 0xa61be758, 0x593c2626, 333 }, - { 0xb6e0c377, 0xcfa2e12e, 0x6f8b2fb0, 336 }, - { 0xe498f455, 0xc38b997a, 0x0b6dfb9c, 339 }, - { 0x8edf98b5, 0x9a373fec, 0x4724bd41, 343 }, - { 0xb2977ee3, 0x00c50fe7, 0x58edec91, 346 }, - { 0xdf3d5e9b, 0xc0f653e1, 0x2f2967b6, 349 }, - { 0x8b865b21, 0x5899f46c, 0xbd79e0d2, 353 }, - { 0xae67f1e9, 0xaec07187, 0xecd85906, 356 }, - { 0xda01ee64, 0x1a708de9, 0xe80e6f48, 359 }, - { 0x884134fe, 0x908658b2, 0x3109058d, 363 }, - { 0xaa51823e, 0x34a7eede, 0xbd4b46f0, 366 }, - { 0xd4e5e2cd, 0xc1d1ea96, 0x6c9e18ac, 369 }, - { 0x850fadc0, 0x9923329e, 0x03e2cf6b, 373 }, - { 0xa6539930, 0xbf6bff45, 0x84db8346, 376 }, - { 0xcfe87f7c, 0xef46ff16, 0xe6126418, 379 }, - { 0x81f14fae, 0x158c5f6e, 0x4fcb7e8f, 383 }, - { 0xa26da399, 0x9aef7749, 0xe3be5e33, 386 }, - { 0xcb090c80, 0x01ab551c, 0x5cadf5bf, 389 }, - { 0xfdcb4fa0, 0x02162a63, 0x73d9732f, 392 }, - { 0x9e9f11c4, 0x014dda7e, 0x2867e7fd, 396 }, - { 0xc646d635, 0x01a1511d, 0xb281e1fd, 399 }, - { 0xf7d88bc2, 0x4209a565, 0x1f225a7c, 402 }, - { 0x9ae75759, 0x6946075f, 0x3375788d, 406 }, - { 0xc1a12d2f, 0xc3978937, 0x0052d6b1, 409 }, - { 0xf209787b, 0xb47d6b84, 0xc0678c5d, 412 }, - { 0x9745eb4d, 0x50ce6332, 0xf840b7ba, 416 }, - { 0xbd176620, 0xa501fbff, 0xb650e5a9, 419 }, - { 0xec5d3fa8, 0xce427aff, 0xa3e51f13, 422 }, - { 0x93ba47c9, 0x80e98cdf, 0xc66f336c, 426 }, - { 0xb8a8d9bb, 0xe123f017, 0xb80b0047, 429 }, - { 0xe6d3102a, 0xd96cec1d, 0xa60dc059, 432 }, - { 0x9043ea1a, 0xc7e41392, 0x87c89837, 436 }, - { 0xb454e4a1, 0x79dd1877, 0x29babe45, 439 }, - { 0xe16a1dc9, 0xd8545e94, 0xf4296dd6, 442 }, - { 0x8ce2529e, 0x2734bb1d, 0x1899e4a6, 446 }, - { 0xb01ae745, 0xb101e9e4, 0x5ec05dcf, 449 }, - { 0xdc21a117, 0x1d42645d, 0x76707543, 452 }, - { 0x899504ae, 0x72497eba, 0x6a06494a, 456 }, - { 0xabfa45da, 0x0edbde69, 0x0487db9d, 459 }, - { 0xd6f8d750, 0x9292d603, 0x45a9d284, 462 }, - { 0x865b8692, 0x5b9bc5c2, 0x0b8a2392, 466 }, - { 0xa7f26836, 0xf282b732, 0x8e6cac77, 469 }, - { 0xd1ef0244, 0xaf2364ff, 0x3207d795, 472 }, - { 0x8335616a, 0xed761f1f, 0x7f44e6bd, 476 }, - { 0xa402b9c5, 0xa8d3a6e7, 0x5f16206c, 479 }, - { 0xcd036837, 0x130890a1, 0x36dba887, 482 }, - { 0x80222122, 0x6be55a64, 0xc2494954, 486 }, - { 0xa02aa96b, 0x06deb0fd, 0xf2db9baa, 489 }, - { 0xc83553c5, 0xc8965d3d, 0x6f928294, 492 }, - { 0xfa42a8b7, 0x3abbf48c, 0xcb772339, 495 }, - { 0x9c69a972, 0x84b578d7, 0xff2a7604, 499 }, - { 0xc38413cf, 0x25e2d70d, 0xfef51385, 502 }, - { 0xf46518c2, 0xef5b8cd1, 0x7eb25866, 505 }, - { 0x98bf2f79, 0xd5993802, 0xef2f773f, 509 }, - { 0xbeeefb58, 0x4aff8603, 0xaafb550f, 512 }, - { 0xeeaaba2e, 0x5dbf6784, 0x95ba2a53, 515 }, - { 0x952ab45c, 0xfa97a0b2, 0xdd945a74, 519 }, - { 0xba756174, 0x393d88df, 0x94f97111, 522 }, - { 0xe912b9d1, 0x478ceb17, 0x7a37cd56, 525 }, - { 0x91abb422, 0xccb812ee, 0xac62e055, 529 }, - { 0xb616a12b, 0x7fe617aa, 0x577b986b, 532 }, - { 0xe39c4976, 0x5fdf9d94, 0xed5a7e85, 535 }, - { 0x8e41ade9, 0xfbebc27d, 0x14588f13, 539 }, - { 0xb1d21964, 0x7ae6b31c, 0x596eb2d8, 542 }, - { 0xde469fbd, 0x99a05fe3, 0x6fca5f8e, 545 }, - { 0x8aec23d6, 0x80043bee, 0x25de7bb9, 549 }, - { 0xada72ccc, 0x20054ae9, 0xaf561aa7, 552 }, - { 0xd910f7ff, 0x28069da4, 0x1b2ba151, 555 }, - { 0x87aa9aff, 0x79042286, 0x90fb44d2, 559 }, - { 0xa99541bf, 0x57452b28, 0x353a1607, 562 }, - { 0xd3fa922f, 0x2d1675f2, 0x42889b89, 565 }, - { 0x847c9b5d, 0x7c2e09b7, 0x69956135, 569 }, - { 0xa59bc234, 0xdb398c25, 0x43fab983, 572 }, - { 0xcf02b2c2, 0x1207ef2e, 0x94f967e4, 575 }, - { 0x8161afb9, 0x4b44f57d, 0x1d1be0ee, 579 }, - { 0xa1ba1ba7, 0x9e1632dc, 0x6462d92a, 582 }, - { 0xca28a291, 0x859bbf93, 0x7d7b8f75, 585 }, - { 0xfcb2cb35, 0xe702af78, 0x5cda7352, 588 }, - { 0x9defbf01, 0xb061adab, 0x3a088813, 592 }, - { 0xc56baec2, 0x1c7a1916, 0x088aaa18, 595 }, - { 0xf6c69a72, 0xa3989f5b, 0x8aad549e, 598 }, - { 0x9a3c2087, 0xa63f6399, 0x36ac54e2, 602 }, - { 0xc0cb28a9, 0x8fcf3c7f, 0x84576a1b, 605 }, - { 0xf0fdf2d3, 0xf3c30b9f, 0x656d44a2, 608 }, - { 0x969eb7c4, 0x7859e743, 0x9f644ae5, 612 }, - { 0xbc4665b5, 0x96706114, 0x873d5d9f, 615 }, - { 0xeb57ff22, 0xfc0c7959, 0xa90cb506, 618 }, - { 0x9316ff75, 0xdd87cbd8, 0x09a7f124, 622 }, - { 0xb7dcbf53, 0x54e9bece, 0x0c11ed6d, 625 }, - { 0xe5d3ef28, 0x2a242e81, 0x8f1668c8, 628 }, - { 0x8fa47579, 0x1a569d10, 0xf96e017d, 632 }, - { 0xb38d92d7, 0x60ec4455, 0x37c981dc, 635 }, - { 0xe070f78d, 0x3927556a, 0x85bbe253, 638 }, - { 0x8c469ab8, 0x43b89562, 0x93956d74, 642 }, - { 0xaf584166, 0x54a6babb, 0x387ac8d1, 645 }, - { 0xdb2e51bf, 0xe9d0696a, 0x06997b05, 648 }, - { 0x88fcf317, 0xf22241e2, 0x441fece3, 652 }, - { 0xab3c2fdd, 0xeeaad25a, 0xd527e81c, 655 }, - { 0xd60b3bd5, 0x6a5586f1, 0x8a71e223, 658 }, - { 0x85c70565, 0x62757456, 0xf6872d56, 662 }, - { 0xa738c6be, 0xbb12d16c, 0xb428f8ac, 665 }, - { 0xd106f86e, 0x69d785c7, 0xe13336d7, 668 }, - { 0x82a45b45, 0x0226b39c, 0xecc00246, 672 }, - { 0xa34d7216, 0x42b06084, 0x27f002d7, 675 }, - { 0xcc20ce9b, 0xd35c78a5, 0x31ec038d, 678 }, - { 0xff290242, 0xc83396ce, 0x7e670471, 681 }, - { 0x9f79a169, 0xbd203e41, 0x0f0062c6, 685 }, - { 0xc75809c4, 0x2c684dd1, 0x52c07b78, 688 }, - { 0xf92e0c35, 0x37826145, 0xa7709a56, 691 }, - { 0x9bbcc7a1, 0x42b17ccb, 0x88a66076, 695 }, - { 0xc2abf989, 0x935ddbfe, 0x6acff893, 698 }, - { 0xf356f7eb, 0xf83552fe, 0x0583f6b8, 701 }, - { 0x98165af3, 0x7b2153de, 0xc3727a33, 705 }, - { 0xbe1bf1b0, 0x59e9a8d6, 0x744f18c0, 708 }, - { 0xeda2ee1c, 0x7064130c, 0x1162def0, 711 }, - { 0x9485d4d1, 0xc63e8be7, 0x8addcb56, 715 }, - { 0xb9a74a06, 0x37ce2ee1, 0x6d953e2b, 718 }, - { 0xe8111c87, 0xc5c1ba99, 0xc8fa8db6, 721 }, - { 0x910ab1d4, 0xdb9914a0, 0x1d9c9892, 725 }, - { 0xb54d5e4a, 0x127f59c8, 0x2503beb6, 728 }, - { 0xe2a0b5dc, 0x971f303a, 0x2e44ae64, 731 }, - { 0x8da471a9, 0xde737e24, 0x5ceaecfe, 735 }, - { 0xb10d8e14, 0x56105dad, 0x7425a83e, 738 }, - { 0xdd50f199, 0x6b947518, 0xd12f124e, 741 }, - { 0x8a5296ff, 0xe33cc92f, 0x82bd6b70, 745 }, - { 0xace73cbf, 0xdc0bfb7b, 0x636cc64d, 748 }, - { 0xd8210bef, 0xd30efa5a, 0x3c47f7e0, 751 }, - { 0x8714a775, 0xe3e95c78, 0x65acfaec, 755 }, - { 0xa8d9d153, 0x5ce3b396, 0x7f1839a7, 758 }, - { 0xd31045a8, 0x341ca07c, 0x1ede4811, 761 }, - { 0x83ea2b89, 0x2091e44d, 0x934aed0a, 765 }, - { 0xa4e4b66b, 0x68b65d60, 0xf81da84d, 768 }, - { 0xce1de406, 0x42e3f4b9, 0x36251260, 771 }, - { 0x80d2ae83, 0xe9ce78f3, 0xc1d72b7c, 775 }, - { 0xa1075a24, 0xe4421730, 0xb24cf65b, 778 }, - { 0xc94930ae, 0x1d529cfc, 0xdee033f2, 781 }, - { 0xfb9b7cd9, 0xa4a7443c, 0x169840ef, 784 }, - { 0x9d412e08, 0x06e88aa5, 0x8e1f2895, 788 }, - { 0xc491798a, 0x08a2ad4e, 0xf1a6f2ba, 791 }, - { 0xf5b5d7ec, 0x8acb58a2, 0xae10af69, 794 }, - { 0x9991a6f3, 0xd6bf1765, 0xacca6da1, 798 }, - { 0xbff610b0, 0xcc6edd3f, 0x17fd090a, 801 }, - { 0xeff394dc, 0xff8a948e, 0xddfc4b4c, 804 }, - { 0x95f83d0a, 0x1fb69cd9, 0x4abdaf10, 808 }, - { 0xbb764c4c, 0xa7a4440f, 0x9d6d1ad4, 811 }, - { 0xea53df5f, 0xd18d5513, 0x84c86189, 814 }, - { 0x92746b9b, 0xe2f8552c, 0x32fd3cf5, 818 }, - { 0xb7118682, 0xdbb66a77, 0x3fbc8c33, 821 }, - { 0xe4d5e823, 0x92a40515, 0x0fabaf3f, 824 }, - { 0x8f05b116, 0x3ba6832d, 0x29cb4d87, 828 }, - { 0xb2c71d5b, 0xca9023f8, 0x743e20e9, 831 }, - { 0xdf78e4b2, 0xbd342cf6, 0x914da924, 834 }, - { 0x8bab8eef, 0xb6409c1a, 0x1ad089b6, 838 }, - { 0xae9672ab, 0xa3d0c320, 0xa184ac24, 841 }, - { 0xda3c0f56, 0x8cc4f3e8, 0xc9e5d72d, 844 }, - { 0x88658996, 0x17fb1871, 0x7e2fa67c, 848 }, - { 0xaa7eebfb, 0x9df9de8d, 0xddbb901b, 851 }, - { 0xd51ea6fa, 0x85785631, 0x552a7422, 854 }, - { 0x8533285c, 0x936b35de, 0xd53a8895, 858 }, - { 0xa67ff273, 0xb8460356, 0x8a892aba, 861 }, - { 0xd01fef10, 0xa657842c, 0x2d2b7569, 864 }, - { 0x8213f56a, 0x67f6b29b, 0x9c3b2962, 868 }, - { 0xa298f2c5, 0x01f45f42, 0x8349f3ba, 871 }, - { 0xcb3f2f76, 0x42717713, 0x241c70a9, 874 }, - { 0xfe0efb53, 0xd30dd4d7, 0xed238cd3, 877 }, - { 0x9ec95d14, 0x63e8a506, 0xf4363804, 881 }, - { 0xc67bb459, 0x7ce2ce48, 0xb143c605, 884 }, - { 0xf81aa16f, 0xdc1b81da, 0xdd94b786, 887 }, - { 0x9b10a4e5, 0xe9913128, 0xca7cf2b4, 891 }, - { 0xc1d4ce1f, 0x63f57d72, 0xfd1c2f61, 894 }, - { 0xf24a01a7, 0x3cf2dccf, 0xbc633b39, 897 }, - { 0x976e4108, 0x8617ca01, 0xd5be0503, 901 }, - { 0xbd49d14a, 0xa79dbc82, 0x4b2d8644, 904 }, - { 0xec9c459d, 0x51852ba2, 0xddf8e7d6, 907 }, - { 0x93e1ab82, 0x52f33b45, 0xcabb90e5, 911 }, - { 0xb8da1662, 0xe7b00a17, 0x3d6a751f, 914 }, - { 0xe7109bfb, 0xa19c0c9d, 0x0cc51267, 917 }, - { 0x906a617d, 0x450187e2, 0x27fb2b80, 921 }, - { 0xb484f9dc, 0x9641e9da, 0xb1f9f660, 924 }, - { 0xe1a63853, 0xbbd26451, 0x5e7873f8, 927 }, - { 0x8d07e334, 0x55637eb2, 0xdb0b487b, 931 }, - { 0xb049dc01, 0x6abc5e5f, 0x91ce1a9a, 934 }, - { 0xdc5c5301, 0xc56b75f7, 0x7641a140, 937 }, - { 0x89b9b3e1, 0x1b6329ba, 0xa9e904c8, 941 }, - { 0xac2820d9, 0x623bf429, 0x546345fa, 944 }, - { 0xd732290f, 0xbacaf133, 0xa97c1779, 947 }, - { 0x867f59a9, 0xd4bed6c0, 0x49ed8eab, 951 }, - { 0xa81f3014, 0x49ee8c70, 0x5c68f256, 954 }, - { 0xd226fc19, 0x5c6a2f8c, 0x73832eec, 957 }, - { 0x83585d8f, 0xd9c25db7, 0xc831fd53, 961 }, - { 0xa42e74f3, 0xd032f525, 0xba3e7ca8, 964 }, - { 0xcd3a1230, 0xc43fb26f, 0x28ce1bd2, 967 }, - { 0x80444b5e, 0x7aa7cf85, 0x7980d163, 971 }, - { 0xa0555e36, 0x1951c366, 0xd7e105bc, 974 }, - { 0xc86ab5c3, 0x9fa63440, 0x8dd9472b, 977 }, - { 0xfa856334, 0x878fc150, 0xb14f98f6, 980 }, - { 0x9c935e00, 0xd4b9d8d2, 0x6ed1bf9a, 984 }, - { 0xc3b83581, 0x09e84f07, 0x0a862f80, 987 }, - { 0xf4a642e1, 0x4c6262c8, 0xcd27bb61, 990 }, - { 0x98e7e9cc, 0xcfbd7dbd, 0x8038d51c, 994 }, - { 0xbf21e440, 0x03acdd2c, 0xe0470a63, 997 }, - { 0xeeea5d50, 0x04981478, 0x1858ccfc, 1000 }, - { 0x95527a52, 0x02df0ccb, 0x0f37801e, 1004 }, - { 0xbaa718e6, 0x8396cffd, 0xd3056025, 1007 }, - { 0xe950df20, 0x247c83fd, 0x47c6b82e, 1010 }, - { 0x91d28b74, 0x16cdd27e, 0x4cdc331d, 1014 }, - { 0xb6472e51, 0x1c81471d, 0xe0133fe4, 1017 }, - { 0xe3d8f9e5, 0x63a198e5, 0x58180fdd, 1020 }, - { 0x8e679c2f, 0x5e44ff8f, 0x570f09ea, 1024 }, - { 0xb201833b, 0x35d63f73, 0x2cd2cc65, 1027 }, - { 0xde81e40a, 0x034bcf4f, 0xf8077f7e, 1030 }, - { 0x8b112e86, 0x420f6191, 0xfb04afaf, 1034 }, - { 0xadd57a27, 0xd29339f6, 0x79c5db9a, 1037 }, - { 0xd94ad8b1, 0xc7380874, 0x18375281, 1040 }, - { 0x87cec76f, 0x1c830548, 0x8f229391, 1044 }, - { 0xa9c2794a, 0xe3a3c69a, 0xb2eb3875, 1047 }, - { 0xd433179d, 0x9c8cb841, 0x5fa60692, 1050 }, - { 0x849feec2, 0x81d7f328, 0xdbc7c41b, 1054 }, - { 0xa5c7ea73, 0x224deff3, 0x12b9b522, 1057 }, - { 0xcf39e50f, 0xeae16bef, 0xd768226b, 1060 }, - { 0x81842f29, 0xf2cce375, 0xe6a11583, 1064 }, - { 0xa1e53af4, 0x6f801c53, 0x60495ae3, 1067 }, - { 0xca5e89b1, 0x8b602368, 0x385bb19c, 1070 }, - { 0xfcf62c1d, 0xee382c42, 0x46729e03, 1073 }, - { 0x9e19db92, 0xb4e31ba9, 0x6c07a2c2, 1077 } - }; - static const short int Lhint[2098] = { - /*18,*/19, 19, 19, 19, 20, 20, 20, 21, 21, - 21, 22, 22, 22, 23, 23, 23, 23, 24, 24, - 24, 25, 25, 25, 26, 26, 26, 26, 27, 27, - 27, 28, 28, 28, 29, 29, 29, 29, 30, 30, - 30, 31, 31, 31, 32, 32, 32, 32, 33, 33, - 33, 34, 34, 34, 35, 35, 35, 35, 36, 36, - 36, 37, 37, 37, 38, 38, 38, 38, 39, 39, - 39, 40, 40, 40, 41, 41, 41, 41, 42, 42, - 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, - 45, 46, 46, 46, 47, 47, 47, 47, 48, 48, - 48, 49, 49, 49, 50, 50, 50, 51, 51, 51, - 51, 52, 52, 52, 53, 53, 53, 54, 54, 54, - 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, - 57, 58, 58, 58, 59, 59, 59, 60, 60, 60, - 60, 61, 61, 61, 62, 62, 62, 63, 63, 63, - 63, 64, 64, 64, 65, 65, 65, 66, 66, 66, - 66, 67, 67, 67, 68, 68, 68, 69, 69, 69, - 69, 70, 70, 70, 71, 71, 71, 72, 72, 72, - 72, 73, 73, 73, 74, 74, 74, 75, 75, 75, - 75, 76, 76, 76, 77, 77, 77, 78, 78, 78, - 78, 79, 79, 79, 80, 80, 80, 81, 81, 81, - 82, 82, 82, 82, 83, 83, 83, 84, 84, 84, - 85, 85, 85, 85, 86, 86, 86, 87, 87, 87, - 88, 88, 88, 88, 89, 89, 89, 90, 90, 90, - 91, 91, 91, 91, 92, 92, 92, 93, 93, 93, - 94, 94, 94, 94, 95, 95, 95, 96, 96, 96, - 97, 97, 97, 97, 98, 98, 98, 99, 99, 99, - 100, 100, 100, 100, 101, 101, 101, 102, 102, 102, - 103, 103, 103, 103, 104, 104, 104, 105, 105, 105, - 106, 106, 106, 106, 107, 107, 107, 108, 108, 108, - 109, 109, 109, 110, 110, 110, 110, 111, 111, 111, - 112, 112, 112, 113, 113, 113, 113, 114, 114, 114, - 115, 115, 115, 116, 116, 116, 116, 117, 117, 117, - 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, - 121, 121, 121, 122, 122, 122, 122, 123, 123, 123, - 124, 124, 124, 125, 125, 125, 125, 126, 126, 126, - 127, 127, 127, 128, 128, 128, 128, 129, 129, 129, - 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, - 133, 133, 133, 134, 134, 134, 134, 135, 135, 135, - 136, 136, 136, 137, 137, 137, 137, 138, 138, 138, - 139, 139, 139, 140, 140, 140, 141, 141, 141, 141, - 142, 142, 142, 143, 143, 143, 144, 144, 144, 144, - 145, 145, 145, 146, 146, 146, 147, 147, 147, 147, - 148, 148, 148, 149, 149, 149, 150, 150, 150, 150, - 151, 151, 151, 152, 152, 152, 153, 153, 153, 153, - 154, 154, 154, 155, 155, 155, 156, 156, 156, 156, - 157, 157, 157, 158, 158, 158, 159, 159, 159, 159, - 160, 160, 160, 161, 161, 161, 162, 162, 162, 162, - 163, 163, 163, 164, 164, 164, 165, 165, 165, 165, - 166, 166, 166, 167, 167, 167, 168, 168, 168, 169, - 169, 169, 169, 170, 170, 170, 171, 171, 171, 172, - 172, 172, 172, 173, 173, 173, 174, 174, 174, 175, - 175, 175, 175, 176, 176, 176, 177, 177, 177, 178, - 178, 178, 178, 179, 179, 179, 180, 180, 180, 181, - 181, 181, 181, 182, 182, 182, 183, 183, 183, 184, - 184, 184, 184, 185, 185, 185, 186, 186, 186, 187, - 187, 187, 187, 188, 188, 188, 189, 189, 189, 190, - 190, 190, 190, 191, 191, 191, 192, 192, 192, 193, - 193, 193, 193, 194, 194, 194, 195, 195, 195, 196, - 196, 196, 197, 197, 197, 197, 198, 198, 198, 199, - 199, 199, 200, 200, 200, 200, 201, 201, 201, 202, - 202, 202, 203, 203, 203, 203, 204, 204, 204, 205, - 205, 205, 206, 206, 206, 206, 207, 207, 207, 208, - 208, 208, 209, 209, 209, 209, 210, 210, 210, 211, - 211, 211, 212, 212, 212, 212, 213, 213, 213, 214, - 214, 214, 215, 215, 215, 215, 216, 216, 216, 217, - 217, 217, 218, 218, 218, 218, 219, 219, 219, 220, - 220, 220, 221, 221, 221, 221, 222, 222, 222, 223, - 223, 223, 224, 224, 224, 224, 225, 225, 225, 226, - 226, 226, 227, 227, 227, 228, 228, 228, 228, 229, - 229, 229, 230, 230, 230, 231, 231, 231, 231, 232, - 232, 232, 233, 233, 233, 234, 234, 234, 234, 235, - 235, 235, 236, 236, 236, 237, 237, 237, 237, 238, - 238, 238, 239, 239, 239, 240, 240, 240, 240, 241, - 241, 241, 242, 242, 242, 243, 243, 243, 243, 244, - 244, 244, 245, 245, 245, 246, 246, 246, 246, 247, - 247, 247, 248, 248, 248, 249, 249, 249, 249, 250, - 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, - 253, 253, 254, 254, 254, 255, 255, 255, 256, 256, - 256, 256, 257, 257, 257, 258, 258, 258, 259, 259, - 259, 259, 260, 260, 260, 261, 261, 261, 262, 262, - 262, 262, 263, 263, 263, 264, 264, 264, 265, 265, - 265, 265, 266, 266, 266, 267, 267, 267, 268, 268, - 268, 268, 269, 269, 269, 270, 270, 270, 271, 271, - 271, 271, 272, 272, 272, 273, 273, 273, 274, 274, - 274, 274, 275, 275, 275, 276, 276, 276, 277, 277, - 277, 277, 278, 278, 278, 279, 279, 279, 280, 280, - 280, 280, 281, 281, 281, 282, 282, 282, 283, 283, - 283, 283, 284, 284, 284, 285, 285, 285, 286, 286, - 286, 287, 287, 287, 287, 288, 288, 288, 289, 289, - 289, 290, 290, 290, 290, 291, 291, 291, 292, 292, - 292, 293, 293, 293, 293, 294, 294, 294, 295, 295, - 295, 296, 296, 296, 296, 297, 297, 297, 298, 298, - 298, 299, 299, 299, 299, 300, 300, 300, 301, 301, - 301, 302, 302, 302, 302, 303, 303, 303, 304, 304, - 304, 305, 305, 305, 305, 306, 306, 306, 307, 307, - 307, 308, 308, 308, 308, 309, 309, 309, 310, 310, - 310, 311, 311, 311, 311, 312, 312, 312, 313, 313, - 313, 314, 314, 314, 315, 315, 315, 315, 316, 316, - 316, 317, 317, 317, 318, 318, 318, 318, 319, 319, - 319, 320, 320, 320, 321, 321, 321, 321, 322, 322, - 322, 323, 323, 323, 324, 324, 324, 324, 325, 325, - 325, 326, 326, 326, 327, 327, 327, 327, 328, 328, - 328, 329, 329, 329, 330, 330, 330, 330, 331, 331, - 331, 332, 332, 332, 333, 333, 333, 333, 334, 334, - 334, 335, 335, 335, 336, 336, 336, 336, 337, 337, - 337, 338, 338, 338, 339, 339, 339, 339, 340, 340, - 340, 341, 341, 341, 342, 342, 342, 342, 343, 343, - 343, 344, 344, 344, 345, 345, 345, 346, 346, 346, - 346, 347, 347, 347, 348, 348, 348, 349, 349, 349, - 349, 350, 350, 350, 351, 351, 351, 352, 352, 352, - 352, 353, 353, 353, 354, 354, 354, 355, 355, 355, - 355, 356, 356, 356, 357, 357, 357, 358, 358, 358, - 358, 359, 359, 359, 360, 360, 360, 361, 361, 361, - 361, 362, 362, 362, 363, 363, 363, 364, 364, 364, - 364, 365, 365, 365, 366, 366, 366, 367, 367, 367, - 367, 368, 368, 368, 369, 369, 369, 370, 370, 370, - 370, 371, 371, 371, 372, 372, 372, 373, 373, 373, - 374, 374, 374, 374, 375, 375, 375, 376, 376, 376, - 377, 377, 377, 377, 378, 378, 378, 379, 379, 379, - 380, 380, 380, 380, 381, 381, 381, 382, 382, 382, - 383, 383, 383, 383, 384, 384, 384, 385, 385, 385, - 386, 386, 386, 386, 387, 387, 387, 388, 388, 388, - 389, 389, 389, 389, 390, 390, 390, 391, 391, 391, - 392, 392, 392, 392, 393, 393, 393, 394, 394, 394, - 395, 395, 395, 395, 396, 396, 396, 397, 397, 397, - 398, 398, 398, 398, 399, 399, 399, 400, 400, 400, - 401, 401, 401, 402, 402, 402, 402, 403, 403, 403, - 404, 404, 404, 405, 405, 405, 405, 406, 406, 406, - 407, 407, 407, 408, 408, 408, 408, 409, 409, 409, - 410, 410, 410, 411, 411, 411, 411, 412, 412, 412, - 413, 413, 413, 414, 414, 414, 414, 415, 415, 415, - 416, 416, 416, 417, 417, 417, 417, 418, 418, 418, - 419, 419, 419, 420, 420, 420, 420, 421, 421, 421, - 422, 422, 422, 423, 423, 423, 423, 424, 424, 424, - 425, 425, 425, 426, 426, 426, 426, 427, 427, 427, - 428, 428, 428, 429, 429, 429, 429, 430, 430, 430, - 431, 431, 431, 432, 432, 432, 433, 433, 433, 433, - 434, 434, 434, 435, 435, 435, 436, 436, 436, 436, - 437, 437, 437, 438, 438, 438, 439, 439, 439, 439, - 440, 440, 440, 441, 441, 441, 442, 442, 442, 442, - 443, 443, 443, 444, 444, 444, 445, 445, 445, 445, - 446, 446, 446, 447, 447, 447, 448, 448, 448, 448, - 449, 449, 449, 450, 450, 450, 451, 451, 451, 451, - 452, 452, 452, 453, 453, 453, 454, 454, 454, 454, - 455, 455, 455, 456, 456, 456, 457, 457, 457, 457, - 458, 458, 458, 459, 459, 459, 460, 460, 460, 461, - 461, 461, 461, 462, 462, 462, 463, 463, 463, 464, - 464, 464, 464, 465, 465, 465, 466, 466, 466, 467, - 467, 467, 467, 468, 468, 468, 469, 469, 469, 470, - 470, 470, 470, 471, 471, 471, 472, 472, 472, 473, - 473, 473, 473, 474, 474, 474, 475, 475, 475, 476, - 476, 476, 476, 477, 477, 477, 478, 478, 478, 479, - 479, 479, 479, 480, 480, 480, 481, 481, 481, 482, - 482, 482, 482, 483, 483, 483, 484, 484, 484, 485, - 485, 485, 485, 486, 486, 486, 487, 487, 487, 488, - 488, 488, 488, 489, 489, 489, 490, 490, 490, 491, - 491, 491, 492, 492, 492, 492, 493, 493, 493, 494, - 494, 494, 495, 495, 495, 495, 496, 496, 496, 497, - 497, 497, 498, 498, 498, 498, 499, 499, 499, 500, - 500, 500, 501, 501, 501, 501, 502, 502, 502, 503, - 503, 503, 504, 504, 504, 504, 505, 505, 505, 506, - 506, 506, 507, 507, 507, 507, 508, 508, 508, 509, - 509, 509, 510, 510, 510, 510, 511, 511, 511, 512, - 512, 512, 513, 513, 513, 513, 514, 514, 514, 515, - 515, 515, 516, 516, 516, 516, 517, 517, 517, 518, - 518, 518, 519, 519, 519, 520, 520, 520, 520, 521, - 521, 521, 522, 522, 522, 523, 523, 523, 523, 524, - 524, 524, 525, 525, 525, 526, 526, 526, 526, 527, - 527, 527, 528, 528, 528, 529, 529, 529, 529, 530, - 530, 530, 531, 531, 531, 532, 532, 532, 532, 533, - 533, 533, 534, 534, 534, 535, 535, 535, 535, 536, - 536, 536, 537, 537, 537, 538, 538, 538, 538, 539, - 539, 539, 540, 540, 540, 541, 541, 541, 541, 542, - 542, 542, 543, 543, 543, 544, 544, 544, 544, 545, - 545, 545, 546, 546, 546, 547, 547, 547, 548, 548, - 548, 548, 549, 549, 549, 550, 550, 550, 551, 551, - 551, 551, 552, 552, 552, 553, 553, 553, 554, 554, - 554, 554, 555, 555, 555, 556, 556, 556, 557, 557, - 557, 557, 558, 558, 558, 559, 559, 559, 560, 560, - 560, 560, 561, 561, 561, 562, 562, 562, 563, 563, - 563, 563, 564, 564, 564, 565, 565, 565, 566, 566, - 566, 566, 567, 567, 567, 568, 568, 568, 569, 569, - 569, 569, 570, 570, 570, 571, 571, 571, 572, 572, - 572, 572, 573, 573, 573, 574, 574, 574, 575, 575, - 575, 575, 576, 576, 576, 577, 577, 577, 578, 578, - 578, 579, 579, 579, 579, 580, 580, 580, 581, 581, - 581, 582, 582, 582, 582, 583, 583, 583, 584, 584, - 584, 585, 585, 585, 585, 586, 586, 586, 587, 587, - 587, 588, 588, 588, 588, 589, 589, 589, 590, 590, - 590, 591, 591, 591, 591, 592, 592, 592, 593, 593, - 593, 594, 594, 594, 594, 595, 595, 595, 596, 596, - 596, 597, 597, 597, 597, 598, 598, 598, 599, 599, - 599, 600, 600, 600, 600, 601, 601, 601, 602, 602, - 602, 603, 603, 603, 603, 604, 604, 604, 605, 605, - 605, 606, 606, 606, 607, 607, 607, 607, 608, 608, - 608, 609, 609, 609, 610, 610, 610, 610, 611, 611, - 611, 612, 612, 612, 613, 613, 613, 613, 614, 614, - 614, 615, 615, 615, 616, 616, 616, 616, 617, 617, - 617, 618, 618, 618, 619, 619, 619, 619, 620, 620, - 620, 621, 621, 621, 622, 622, 622, 622, 623, 623, - 623, 624, 624, 624, 625, 625, 625, 625, 626, 626, - 626, 627, 627, 627, 628, 628, 628, 628, 629, 629, - 629, 630, 630, 630, 631, 631, 631, 631, 632, 632, - 632, 633, 633, 633, 634, 634, 634, 634, 635, 635, - 635, 636, 636, 636, 637, 637, 637, 638, 638, 638, - 638, 639, 639, 639, 640, 640, 640, 641, 641, 641, - 641, 642, 642, 642, 643, 643, 643, 644, 644, 644, - 644, 645, 645, 645, 646, 646, 646, 647, 647, 647, - 647, 648, 648, 648, 649, 649, 649, 650, 650 }; - static ULLong pfive[27] = { - 5ll, - 25ll, - 125ll, - 625ll, - 3125ll, - 15625ll, - 78125ll, - 390625ll, - 1953125ll, - 9765625ll, - 48828125ll, - 244140625ll, - 1220703125ll, - 6103515625ll, - 30517578125ll, - 152587890625ll, - 762939453125ll, - 3814697265625ll, - 19073486328125ll, - 95367431640625ll, - 476837158203125ll, - 2384185791015625ll, - 11920928955078125ll, - 59604644775390625ll, - 298023223876953125ll, - 1490116119384765625ll, - 7450580596923828125ll - }; +static const BF96 kDtoaPten[667] = {{0xeef453d6, 0x923bd65a, 0x113faa29, -1136}, + {0x9558b466, 0x1b6565f8, 0x4ac7ca59, -1132}, + {0xbaaee17f, 0xa23ebf76, 0x5d79bcf0, -1129}, + {0xe95a99df, 0x8ace6f53, 0xf4d82c2c, -1126}, + {0x91d8a02b, 0xb6c10594, 0x79071b9b, -1122}, + {0xb64ec836, 0xa47146f9, 0x9748e282, -1119}, + {0xe3e27a44, 0x4d8d98b7, 0xfd1b1b23, -1116}, + {0x8e6d8c6a, 0xb0787f72, 0xfe30f0f5, -1112}, + {0xb208ef85, 0x5c969f4f, 0xbdbd2d33, -1109}, + {0xde8b2b66, 0xb3bc4723, 0xad2c7880, -1106}, + {0x8b16fb20, 0x3055ac76, 0x4c3bcb50, -1102}, + {0xaddcb9e8, 0x3c6b1793, 0xdf4abe24, -1099}, + {0xd953e862, 0x4b85dd78, 0xd71d6dad, -1096}, + {0x87d4713d, 0x6f33aa6b, 0x8672648c, -1092}, + {0xa9c98d8c, 0xcb009506, 0x680efdaf, -1089}, + {0xd43bf0ef, 0xfdc0ba48, 0x0212bd1b, -1086}, + {0x84a57695, 0xfe98746d, 0x014bb630, -1082}, + {0xa5ced43b, 0x7e3e9188, 0x419ea3bd, -1079}, + {0xcf42894a, 0x5dce35ea, 0x52064cac, -1076}, + {0x818995ce, 0x7aa0e1b2, 0x7343efeb, -1072}, + {0xa1ebfb42, 0x19491a1f, 0x1014ebe6, -1069}, + {0xca66fa12, 0x9f9b60a6, 0xd41a26e0, -1066}, + {0xfd00b897, 0x478238d0, 0x8920b098, -1063}, + {0x9e20735e, 0x8cb16382, 0x55b46e5f, -1059}, + {0xc5a89036, 0x2fddbc62, 0xeb2189f7, -1056}, + {0xf712b443, 0xbbd52b7b, 0xa5e9ec75, -1053}, + {0x9a6bb0aa, 0x55653b2d, 0x47b233c9, -1049}, + {0xc1069cd4, 0xeabe89f8, 0x999ec0bb, -1046}, + {0xf148440a, 0x256e2c76, 0xc00670ea, -1043}, + {0x96cd2a86, 0x5764dbca, 0x38040692, -1039}, + {0xbc807527, 0xed3e12bc, 0xc6050837, -1036}, + {0xeba09271, 0xe88d976b, 0xf7864a44, -1033}, + {0x93445b87, 0x31587ea3, 0x7ab3ee6a, -1029}, + {0xb8157268, 0xfdae9e4c, 0x5960ea05, -1026}, + {0xe61acf03, 0x3d1a45df, 0x6fb92487, -1023}, + {0x8fd0c162, 0x06306bab, 0xa5d3b6d4, -1019}, + {0xb3c4f1ba, 0x87bc8696, 0x8f48a489, -1016}, + {0xe0b62e29, 0x29aba83c, 0x331acdab, -1013}, + {0x8c71dcd9, 0xba0b4925, 0x9ff0c08b, -1009}, + {0xaf8e5410, 0x288e1b6f, 0x07ecf0ae, -1006}, + {0xdb71e914, 0x32b1a24a, 0xc9e82cd9, -1003}, + {0x892731ac, 0x9faf056e, 0xbe311c08, -999}, + {0xab70fe17, 0xc79ac6ca, 0x6dbd630a, -996}, + {0xd64d3d9d, 0xb981787d, 0x092cbbcc, -993}, + {0x85f04682, 0x93f0eb4e, 0x25bbf560, -989}, + {0xa76c5823, 0x38ed2621, 0xaf2af2b8, -986}, + {0xd1476e2c, 0x07286faa, 0x1af5af66, -983}, + {0x82cca4db, 0x847945ca, 0x50d98d9f, -979}, + {0xa37fce12, 0x6597973c, 0xe50ff107, -976}, + {0xcc5fc196, 0xfefd7d0c, 0x1e53ed49, -973}, + {0xff77b1fc, 0xbebcdc4f, 0x25e8e89c, -970}, + {0x9faacf3d, 0xf73609b1, 0x77b19161, -966}, + {0xc795830d, 0x75038c1d, 0xd59df5b9, -963}, + {0xf97ae3d0, 0xd2446f25, 0x4b057328, -960}, + {0x9becce62, 0x836ac577, 0x4ee367f9, -956}, + {0xc2e801fb, 0x244576d5, 0x229c41f7, -953}, + {0xf3a20279, 0xed56d48a, 0x6b435275, -950}, + {0x9845418c, 0x345644d6, 0x830a1389, -946}, + {0xbe5691ef, 0x416bd60c, 0x23cc986b, -943}, + {0xedec366b, 0x11c6cb8f, 0x2cbfbe86, -940}, + {0x94b3a202, 0xeb1c3f39, 0x7bf7d714, -936}, + {0xb9e08a83, 0xa5e34f07, 0xdaf5ccd9, -933}, + {0xe858ad24, 0x8f5c22c9, 0xd1b3400f, -930}, + {0x91376c36, 0xd99995be, 0x23100809, -926}, + {0xb5854744, 0x8ffffb2d, 0xabd40a0c, -923}, + {0xe2e69915, 0xb3fff9f9, 0x16c90c8f, -920}, + {0x8dd01fad, 0x907ffc3b, 0xae3da7d9, -916}, + {0xb1442798, 0xf49ffb4a, 0x99cd11cf, -913}, + {0xdd95317f, 0x31c7fa1d, 0x40405643, -910}, + {0x8a7d3eef, 0x7f1cfc52, 0x482835ea, -906}, + {0xad1c8eab, 0x5ee43b66, 0xda324365, -903}, + {0xd863b256, 0x369d4a40, 0x90bed43e, -900}, + {0x873e4f75, 0xe2224e68, 0x5a7744a6, -896}, + {0xa90de353, 0x5aaae202, 0x711515d0, -893}, + {0xd3515c28, 0x31559a83, 0x0d5a5b44, -890}, + {0x8412d999, 0x1ed58091, 0xe858790a, -886}, + {0xa5178fff, 0x668ae0b6, 0x626e974d, -883}, + {0xce5d73ff, 0x402d98e3, 0xfb0a3d21, -880}, + {0x80fa687f, 0x881c7f8e, 0x7ce66634, -876}, + {0xa139029f, 0x6a239f72, 0x1c1fffc1, -873}, + {0xc9874347, 0x44ac874e, 0xa327ffb2, -870}, + {0xfbe91419, 0x15d7a922, 0x4bf1ff9f, -867}, + {0x9d71ac8f, 0xada6c9b5, 0x6f773fc3, -863}, + {0xc4ce17b3, 0x99107c22, 0xcb550fb4, -860}, + {0xf6019da0, 0x7f549b2b, 0x7e2a53a1, -857}, + {0x99c10284, 0x4f94e0fb, 0x2eda7444, -853}, + {0xc0314325, 0x637a1939, 0xfa911155, -850}, + {0xf03d93ee, 0xbc589f88, 0x793555ab, -847}, + {0x96267c75, 0x35b763b5, 0x4bc1558b, -843}, + {0xbbb01b92, 0x83253ca2, 0x9eb1aaed, -840}, + {0xea9c2277, 0x23ee8bcb, 0x465e15a9, -837}, + {0x92a1958a, 0x7675175f, 0x0bfacd89, -833}, + {0xb749faed, 0x14125d36, 0xcef980ec, -830}, + {0xe51c79a8, 0x5916f484, 0x82b7e127, -827}, + {0x8f31cc09, 0x37ae58d2, 0xd1b2ecb8, -823}, + {0xb2fe3f0b, 0x8599ef07, 0x861fa7e6, -820}, + {0xdfbdcece, 0x67006ac9, 0x67a791e0, -817}, + {0x8bd6a141, 0x006042bd, 0xe0c8bb2c, -813}, + {0xaecc4991, 0x4078536d, 0x58fae9f7, -810}, + {0xda7f5bf5, 0x90966848, 0xaf39a475, -807}, + {0x888f9979, 0x7a5e012d, 0x6d8406c9, -803}, + {0xaab37fd7, 0xd8f58178, 0xc8e5087b, -800}, + {0xd5605fcd, 0xcf32e1d6, 0xfb1e4a9a, -797}, + {0x855c3be0, 0xa17fcd26, 0x5cf2eea0, -793}, + {0xa6b34ad8, 0xc9dfc06f, 0xf42faa48, -790}, + {0xd0601d8e, 0xfc57b08b, 0xf13b94da, -787}, + {0x823c1279, 0x5db6ce57, 0x76c53d08, -783}, + {0xa2cb1717, 0xb52481ed, 0x54768c4b, -780}, + {0xcb7ddcdd, 0xa26da268, 0xa9942f5d, -777}, + {0xfe5d5415, 0x0b090b02, 0xd3f93b35, -774}, + {0x9efa548d, 0x26e5a6e1, 0xc47bc501, -770}, + {0xc6b8e9b0, 0x709f109a, 0x359ab641, -767}, + {0xf867241c, 0x8cc6d4c0, 0xc30163d2, -764}, + {0x9b407691, 0xd7fc44f8, 0x79e0de63, -760}, + {0xc2109436, 0x4dfb5636, 0x985915fc, -757}, + {0xf294b943, 0xe17a2bc4, 0x3e6f5b7b, -754}, + {0x979cf3ca, 0x6cec5b5a, 0xa705992c, -750}, + {0xbd8430bd, 0x08277231, 0x50c6ff78, -747}, + {0xece53cec, 0x4a314ebd, 0xa4f8bf56, -744}, + {0x940f4613, 0xae5ed136, 0x871b7795, -740}, + {0xb9131798, 0x99f68584, 0x28e2557b, -737}, + {0xe757dd7e, 0xc07426e5, 0x331aeada, -734}, + {0x9096ea6f, 0x3848984f, 0x3ff0d2c8, -730}, + {0xb4bca50b, 0x065abe63, 0x0fed077a, -727}, + {0xe1ebce4d, 0xc7f16dfb, 0xd3e84959, -724}, + {0x8d3360f0, 0x9cf6e4bd, 0x64712dd7, -720}, + {0xb080392c, 0xc4349dec, 0xbd8d794d, -717}, + {0xdca04777, 0xf541c567, 0xecf0d7a0, -714}, + {0x89e42caa, 0xf9491b60, 0xf41686c4, -710}, + {0xac5d37d5, 0xb79b6239, 0x311c2875, -707}, + {0xd77485cb, 0x25823ac7, 0x7d633293, -704}, + {0x86a8d39e, 0xf77164bc, 0xae5dff9c, -700}, + {0xa8530886, 0xb54dbdeb, 0xd9f57f83, -697}, + {0xd267caa8, 0x62a12d66, 0xd072df63, -694}, + {0x8380dea9, 0x3da4bc60, 0x4247cb9e, -690}, + {0xa4611653, 0x8d0deb78, 0x52d9be85, -687}, + {0xcd795be8, 0x70516656, 0x67902e27, -684}, + {0x806bd971, 0x4632dff6, 0x00ba1cd8, -680}, + {0xa086cfcd, 0x97bf97f3, 0x80e8a40e, -677}, + {0xc8a883c0, 0xfdaf7df0, 0x6122cd12, -674}, + {0xfad2a4b1, 0x3d1b5d6c, 0x796b8057, -671}, + {0x9cc3a6ee, 0xc6311a63, 0xcbe33036, -667}, + {0xc3f490aa, 0x77bd60fc, 0xbedbfc44, -664}, + {0xf4f1b4d5, 0x15acb93b, 0xee92fb55, -661}, + {0x99171105, 0x2d8bf3c5, 0x751bdd15, -657}, + {0xbf5cd546, 0x78eef0b6, 0xd262d45a, -654}, + {0xef340a98, 0x172aace4, 0x86fb8971, -651}, + {0x9580869f, 0x0e7aac0e, 0xd45d35e6, -647}, + {0xbae0a846, 0xd2195712, 0x89748360, -644}, + {0xe998d258, 0x869facd7, 0x2bd1a438, -641}, + {0x91ff8377, 0x5423cc06, 0x7b6306a3, -637}, + {0xb67f6455, 0x292cbf08, 0x1a3bc84c, -634}, + {0xe41f3d6a, 0x7377eeca, 0x20caba5f, -631}, + {0x8e938662, 0x882af53e, 0x547eb47b, -627}, + {0xb23867fb, 0x2a35b28d, 0xe99e619a, -624}, + {0xdec681f9, 0xf4c31f31, 0x6405fa00, -621}, + {0x8b3c113c, 0x38f9f37e, 0xde83bc40, -617}, + {0xae0b158b, 0x4738705e, 0x9624ab50, -614}, + {0xd98ddaee, 0x19068c76, 0x3badd624, -611}, + {0x87f8a8d4, 0xcfa417c9, 0xe54ca5d7, -607}, + {0xa9f6d30a, 0x038d1dbc, 0x5e9fcf4c, -604}, + {0xd47487cc, 0x8470652b, 0x7647c320, -601}, + {0x84c8d4df, 0xd2c63f3b, 0x29ecd9f4, -597}, + {0xa5fb0a17, 0xc777cf09, 0xf4681071, -594}, + {0xcf79cc9d, 0xb955c2cc, 0x7182148d, -591}, + {0x81ac1fe2, 0x93d599bf, 0xc6f14cd8, -587}, + {0xa21727db, 0x38cb002f, 0xb8ada00e, -584}, + {0xca9cf1d2, 0x06fdc03b, 0xa6d90811, -581}, + {0xfd442e46, 0x88bd304a, 0x908f4a16, -578}, + {0x9e4a9cec, 0x15763e2e, 0x9a598e4e, -574}, + {0xc5dd4427, 0x1ad3cdba, 0x40eff1e1, -571}, + {0xf7549530, 0xe188c128, 0xd12bee59, -568}, + {0x9a94dd3e, 0x8cf578b9, 0x82bb74f8, -564}, + {0xc13a148e, 0x3032d6e7, 0xe36a5236, -561}, + {0xf18899b1, 0xbc3f8ca1, 0xdc44e6c3, -558}, + {0x96f5600f, 0x15a7b7e5, 0x29ab103a, -554}, + {0xbcb2b812, 0xdb11a5de, 0x7415d448, -551}, + {0xebdf6617, 0x91d60f56, 0x111b495b, -548}, + {0x936b9fce, 0xbb25c995, 0xcab10dd9, -544}, + {0xb84687c2, 0x69ef3bfb, 0x3d5d514f, -541}, + {0xe65829b3, 0x046b0afa, 0x0cb4a5a3, -538}, + {0x8ff71a0f, 0xe2c2e6dc, 0x47f0e785, -534}, + {0xb3f4e093, 0xdb73a093, 0x59ed2167, -531}, + {0xe0f218b8, 0xd25088b8, 0x306869c1, -528}, + {0x8c974f73, 0x83725573, 0x1e414218, -524}, + {0xafbd2350, 0x644eeacf, 0xe5d1929e, -521}, + {0xdbac6c24, 0x7d62a583, 0xdf45f746, -518}, + {0x894bc396, 0xce5da772, 0x6b8bba8c, -514}, + {0xab9eb47c, 0x81f5114f, 0x066ea92f, -511}, + {0xd686619b, 0xa27255a2, 0xc80a537b, -508}, + {0x8613fd01, 0x45877585, 0xbd06742c, -504}, + {0xa798fc41, 0x96e952e7, 0x2c481138, -501}, + {0xd17f3b51, 0xfca3a7a0, 0xf75a1586, -498}, + {0x82ef8513, 0x3de648c4, 0x9a984d73, -494}, + {0xa3ab6658, 0x0d5fdaf5, 0xc13e60d0, -491}, + {0xcc963fee, 0x10b7d1b3, 0x318df905, -488}, + {0xffbbcfe9, 0x94e5c61f, 0xfdf17746, -485}, + {0x9fd561f1, 0xfd0f9bd3, 0xfeb6ea8b, -481}, + {0xc7caba6e, 0x7c5382c8, 0xfe64a52e, -478}, + {0xf9bd690a, 0x1b68637b, 0x3dfdce7a, -475}, + {0x9c1661a6, 0x51213e2d, 0x06bea10c, -471}, + {0xc31bfa0f, 0xe5698db8, 0x486e494f, -468}, + {0xf3e2f893, 0xdec3f126, 0x5a89dba3, -465}, + {0x986ddb5c, 0x6b3a76b7, 0xf8962946, -461}, + {0xbe895233, 0x86091465, 0xf6bbb397, -458}, + {0xee2ba6c0, 0x678b597f, 0x746aa07d, -455}, + {0x94db4838, 0x40b717ef, 0xa8c2a44e, -451}, + {0xba121a46, 0x50e4ddeb, 0x92f34d62, -448}, + {0xe896a0d7, 0xe51e1566, 0x77b020ba, -445}, + {0x915e2486, 0xef32cd60, 0x0ace1474, -441}, + {0xb5b5ada8, 0xaaff80b8, 0x0d819992, -438}, + {0xe3231912, 0xd5bf60e6, 0x10e1fff6, -435}, + {0x8df5efab, 0xc5979c8f, 0xca8d3ffa, -431}, + {0xb1736b96, 0xb6fd83b3, 0xbd308ff8, -428}, + {0xddd0467c, 0x64bce4a0, 0xac7cb3f6, -425}, + {0x8aa22c0d, 0xbef60ee4, 0x6bcdf07a, -421}, + {0xad4ab711, 0x2eb3929d, 0x86c16c98, -418}, + {0xd89d64d5, 0x7a607744, 0xe871c7bf, -415}, + {0x87625f05, 0x6c7c4a8b, 0x11471cd7, -411}, + {0xa93af6c6, 0xc79b5d2d, 0xd598e40d, -408}, + {0xd389b478, 0x79823479, 0x4aff1d10, -405}, + {0x843610cb, 0x4bf160cb, 0xcedf722a, -401}, + {0xa54394fe, 0x1eedb8fe, 0xc2974eb4, -398}, + {0xce947a3d, 0xa6a9273e, 0x733d2262, -395}, + {0x811ccc66, 0x8829b887, 0x0806357d, -391}, + {0xa163ff80, 0x2a3426a8, 0xca07c2dc, -388}, + {0xc9bcff60, 0x34c13052, 0xfc89b393, -385}, + {0xfc2c3f38, 0x41f17c67, 0xbbac2078, -382}, + {0x9d9ba783, 0x2936edc0, 0xd54b944b, -378}, + {0xc5029163, 0xf384a931, 0x0a9e795e, -375}, + {0xf64335bc, 0xf065d37d, 0x4d4617b5, -372}, + {0x99ea0196, 0x163fa42e, 0x504bced1, -368}, + {0xc06481fb, 0x9bcf8d39, 0xe45ec286, -365}, + {0xf07da27a, 0x82c37088, 0x5d767327, -362}, + {0x964e858c, 0x91ba2655, 0x3a6a07f8, -358}, + {0xbbe226ef, 0xb628afea, 0x890489f7, -355}, + {0xeadab0ab, 0xa3b2dbe5, 0x2b45ac74, -352}, + {0x92c8ae6b, 0x464fc96f, 0x3b0b8bc9, -348}, + {0xb77ada06, 0x17e3bbcb, 0x09ce6ebb, -345}, + {0xe5599087, 0x9ddcaabd, 0xcc420a6a, -342}, + {0x8f57fa54, 0xc2a9eab6, 0x9fa94682, -338}, + {0xb32df8e9, 0xf3546564, 0x47939822, -335}, + {0xdff97724, 0x70297ebd, 0x59787e2b, -332}, + {0x8bfbea76, 0xc619ef36, 0x57eb4edb, -328}, + {0xaefae514, 0x77a06b03, 0xede62292, -325}, + {0xdab99e59, 0x958885c4, 0xe95fab36, -322}, + {0x88b402f7, 0xfd75539b, 0x11dbcb02, -318}, + {0xaae103b5, 0xfcd2a881, 0xd652bdc2, -315}, + {0xd59944a3, 0x7c0752a2, 0x4be76d33, -312}, + {0x857fcae6, 0x2d8493a5, 0x6f70a440, -308}, + {0xa6dfbd9f, 0xb8e5b88e, 0xcb4ccd50, -305}, + {0xd097ad07, 0xa71f26b2, 0x7e2000a4, -302}, + {0x825ecc24, 0xc873782f, 0x8ed40066, -298}, + {0xa2f67f2d, 0xfa90563b, 0x72890080, -295}, + {0xcbb41ef9, 0x79346bca, 0x4f2b40a0, -292}, + {0xfea126b7, 0xd78186bc, 0xe2f610c8, -289}, + {0x9f24b832, 0xe6b0f436, 0x0dd9ca7d, -285}, + {0xc6ede63f, 0xa05d3143, 0x91503d1c, -282}, + {0xf8a95fcf, 0x88747d94, 0x75a44c63, -279}, + {0x9b69dbe1, 0xb548ce7c, 0xc986afbe, -275}, + {0xc24452da, 0x229b021b, 0xfbe85bad, -272}, + {0xf2d56790, 0xab41c2a2, 0xfae27299, -269}, + {0x97c560ba, 0x6b0919a5, 0xdccd879f, -265}, + {0xbdb6b8e9, 0x05cb600f, 0x5400e987, -262}, + {0xed246723, 0x473e3813, 0x290123e9, -259}, + {0x9436c076, 0x0c86e30b, 0xf9a0b672, -255}, + {0xb9447093, 0x8fa89bce, 0xf808e40e, -252}, + {0xe7958cb8, 0x7392c2c2, 0xb60b1d12, -249}, + {0x90bd77f3, 0x483bb9b9, 0xb1c6f22b, -245}, + {0xb4ecd5f0, 0x1a4aa828, 0x1e38aeb6, -242}, + {0xe2280b6c, 0x20dd5232, 0x25c6da63, -239}, + {0x8d590723, 0x948a535f, 0x579c487e, -235}, + {0xb0af48ec, 0x79ace837, 0x2d835a9d, -232}, + {0xdcdb1b27, 0x98182244, 0xf8e43145, -229}, + {0x8a08f0f8, 0xbf0f156b, 0x1b8e9ecb, -225}, + {0xac8b2d36, 0xeed2dac5, 0xe272467e, -222}, + {0xd7adf884, 0xaa879177, 0x5b0ed81d, -219}, + {0x86ccbb52, 0xea94baea, 0x98e94712, -215}, + {0xa87fea27, 0xa539e9a5, 0x3f2398d7, -212}, + {0xd29fe4b1, 0x8e88640e, 0x8eec7f0d, -209}, + {0x83a3eeee, 0xf9153e89, 0x1953cf68, -205}, + {0xa48ceaaa, 0xb75a8e2b, 0x5fa8c342, -202}, + {0xcdb02555, 0x653131b6, 0x3792f412, -199}, + {0x808e1755, 0x5f3ebf11, 0xe2bbd88b, -195}, + {0xa0b19d2a, 0xb70e6ed6, 0x5b6aceae, -192}, + {0xc8de0475, 0x64d20a8b, 0xf245825a, -189}, + {0xfb158592, 0xbe068d2e, 0xeed6e2f0, -186}, + {0x9ced737b, 0xb6c4183d, 0x55464dd6, -182}, + {0xc428d05a, 0xa4751e4c, 0xaa97e14c, -179}, + {0xf5330471, 0x4d9265df, 0xd53dd99f, -176}, + {0x993fe2c6, 0xd07b7fab, 0xe546a803, -172}, + {0xbf8fdb78, 0x849a5f96, 0xde985204, -169}, + {0xef73d256, 0xa5c0f77c, 0x963e6685, -166}, + {0x95a86376, 0x27989aad, 0xdde70013, -162}, + {0xbb127c53, 0xb17ec159, 0x5560c018, -159}, + {0xe9d71b68, 0x9dde71af, 0xaab8f01e, -156}, + {0x92267121, 0x62ab070d, 0xcab39613, -152}, + {0xb6b00d69, 0xbb55c8d1, 0x3d607b97, -149}, + {0xe45c10c4, 0x2a2b3b05, 0x8cb89a7d, -146}, + {0x8eb98a7a, 0x9a5b04e3, 0x77f3608e, -142}, + {0xb267ed19, 0x40f1c61c, 0x55f038b2, -139}, + {0xdf01e85f, 0x912e37a3, 0x6b6c46de, -136}, + {0x8b61313b, 0xbabce2c6, 0x2323ac4b, -132}, + {0xae397d8a, 0xa96c1b77, 0xabec975e, -129}, + {0xd9c7dced, 0x53c72255, 0x96e7bd35, -126}, + {0x881cea14, 0x545c7575, 0x7e50d641, -122}, + {0xaa242499, 0x697392d2, 0xdde50bd1, -119}, + {0xd4ad2dbf, 0xc3d07787, 0x955e4ec6, -116}, + {0x84ec3c97, 0xda624ab4, 0xbd5af13b, -112}, + {0xa6274bbd, 0xd0fadd61, 0xecb1ad8a, -109}, + {0xcfb11ead, 0x453994ba, 0x67de18ed, -106}, + {0x81ceb32c, 0x4b43fcf4, 0x80eacf94, -102}, + {0xa2425ff7, 0x5e14fc31, 0xa1258379, -99}, + {0xcad2f7f5, 0x359a3b3e, 0x096ee458, -96}, + {0xfd87b5f2, 0x8300ca0d, 0x8bca9d6e, -93}, + {0x9e74d1b7, 0x91e07e48, 0x775ea264, -89}, + {0xc6120625, 0x76589dda, 0x95364afe, -86}, + {0xf79687ae, 0xd3eec551, 0x3a83ddbd, -83}, + {0x9abe14cd, 0x44753b52, 0xc4926a96, -79}, + {0xc16d9a00, 0x95928a27, 0x75b7053c, -76}, + {0xf1c90080, 0xbaf72cb1, 0x5324c68b, -73}, + {0x971da050, 0x74da7bee, 0xd3f6fc16, -69}, + {0xbce50864, 0x92111aea, 0x88f4bb1c, -66}, + {0xec1e4a7d, 0xb69561a5, 0x2b31e9e3, -63}, + {0x9392ee8e, 0x921d5d07, 0x3aff322e, -59}, + {0xb877aa32, 0x36a4b449, 0x09befeb9, -56}, + {0xe69594be, 0xc44de15b, 0x4c2ebe68, -53}, + {0x901d7cf7, 0x3ab0acd9, 0x0f9d3701, -49}, + {0xb424dc35, 0x095cd80f, 0x538484c1, -46}, + {0xe12e1342, 0x4bb40e13, 0x2865a5f2, -43}, + {0x8cbccc09, 0x6f5088cb, 0xf93f87b7, -39}, + {0xafebff0b, 0xcb24aafe, 0xf78f69a5, -36}, + {0xdbe6fece, 0xbdedd5be, 0xb573440e, -33}, + {0x89705f41, 0x36b4a597, 0x31680a88, -29}, + {0xabcc7711, 0x8461cefc, 0xfdc20d2b, -26}, + {0xd6bf94d5, 0xe57a42bc, 0x3d329076, -23}, + {0x8637bd05, 0xaf6c69b5, 0xa63f9a49, -19}, + {0xa7c5ac47, 0x1b478423, 0x0fcf80dc, -16}, + {0xd1b71758, 0xe219652b, 0xd3c36113, -13}, + {0x83126e97, 0x8d4fdf3b, 0x645a1cac, -9}, + {0xa3d70a3d, 0x70a3d70a, 0x3d70a3d7, -6}, + {0xcccccccc, 0xcccccccc, 0xcccccccc, -3}, + {0x80000000, 0x00000000, 0x00000000, 1}, + {0xa0000000, 0x00000000, 0x00000000, 4}, + {0xc8000000, 0x00000000, 0x00000000, 7}, + {0xfa000000, 0x00000000, 0x00000000, 10}, + {0x9c400000, 0x00000000, 0x00000000, 14}, + {0xc3500000, 0x00000000, 0x00000000, 17}, + {0xf4240000, 0x00000000, 0x00000000, 20}, + {0x98968000, 0x00000000, 0x00000000, 24}, + {0xbebc2000, 0x00000000, 0x00000000, 27}, + {0xee6b2800, 0x00000000, 0x00000000, 30}, + {0x9502f900, 0x00000000, 0x00000000, 34}, + {0xba43b740, 0x00000000, 0x00000000, 37}, + {0xe8d4a510, 0x00000000, 0x00000000, 40}, + {0x9184e72a, 0x00000000, 0x00000000, 44}, + {0xb5e620f4, 0x80000000, 0x00000000, 47}, + {0xe35fa931, 0xa0000000, 0x00000000, 50}, + {0x8e1bc9bf, 0x04000000, 0x00000000, 54}, + {0xb1a2bc2e, 0xc5000000, 0x00000000, 57}, + {0xde0b6b3a, 0x76400000, 0x00000000, 60}, + {0x8ac72304, 0x89e80000, 0x00000000, 64}, + {0xad78ebc5, 0xac620000, 0x00000000, 67}, + {0xd8d726b7, 0x177a8000, 0x00000000, 70}, + {0x87867832, 0x6eac9000, 0x00000000, 74}, + {0xa968163f, 0x0a57b400, 0x00000000, 77}, + {0xd3c21bce, 0xcceda100, 0x00000000, 80}, + {0x84595161, 0x401484a0, 0x00000000, 84}, + {0xa56fa5b9, 0x9019a5c8, 0x00000000, 87}, + {0xcecb8f27, 0xf4200f3a, 0x00000000, 90}, + {0x813f3978, 0xf8940984, 0x40000000, 94}, + {0xa18f07d7, 0x36b90be5, 0x50000000, 97}, + {0xc9f2c9cd, 0x04674ede, 0xa4000000, 100}, + {0xfc6f7c40, 0x45812296, 0x4d000000, 103}, + {0x9dc5ada8, 0x2b70b59d, 0xf0200000, 107}, + {0xc5371912, 0x364ce305, 0x6c280000, 110}, + {0xf684df56, 0xc3e01bc6, 0xc7320000, 113}, + {0x9a130b96, 0x3a6c115c, 0x3c7f4000, 117}, + {0xc097ce7b, 0xc90715b3, 0x4b9f1000, 120}, + {0xf0bdc21a, 0xbb48db20, 0x1e86d400, 123}, + {0x96769950, 0xb50d88f4, 0x13144480, 127}, + {0xbc143fa4, 0xe250eb31, 0x17d955a0, 130}, + {0xeb194f8e, 0x1ae525fd, 0x5dcfab08, 133}, + {0x92efd1b8, 0xd0cf37be, 0x5aa1cae5, 137}, + {0xb7abc627, 0x050305ad, 0xf14a3d9e, 140}, + {0xe596b7b0, 0xc643c719, 0x6d9ccd05, 143}, + {0x8f7e32ce, 0x7bea5c6f, 0xe4820023, 147}, + {0xb35dbf82, 0x1ae4f38b, 0xdda2802c, 150}, + {0xe0352f62, 0xa19e306e, 0xd50b2037, 153}, + {0x8c213d9d, 0xa502de45, 0x4526f422, 157}, + {0xaf298d05, 0x0e4395d6, 0x9670b12b, 160}, + {0xdaf3f046, 0x51d47b4c, 0x3c0cdd76, 163}, + {0x88d8762b, 0xf324cd0f, 0xa5880a69, 167}, + {0xab0e93b6, 0xefee0053, 0x8eea0d04, 170}, + {0xd5d238a4, 0xabe98068, 0x72a49045, 173}, + {0x85a36366, 0xeb71f041, 0x47a6da2b, 177}, + {0xa70c3c40, 0xa64e6c51, 0x999090b6, 180}, + {0xd0cf4b50, 0xcfe20765, 0xfff4b4e3, 183}, + {0x82818f12, 0x81ed449f, 0xbff8f10e, 187}, + {0xa321f2d7, 0x226895c7, 0xaff72d52, 190}, + {0xcbea6f8c, 0xeb02bb39, 0x9bf4f8a6, 193}, + {0xfee50b70, 0x25c36a08, 0x02f236d0, 196}, + {0x9f4f2726, 0x179a2245, 0x01d76242, 200}, + {0xc722f0ef, 0x9d80aad6, 0x424d3ad2, 203}, + {0xf8ebad2b, 0x84e0d58b, 0xd2e08987, 206}, + {0x9b934c3b, 0x330c8577, 0x63cc55f4, 210}, + {0xc2781f49, 0xffcfa6d5, 0x3cbf6b71, 213}, + {0xf316271c, 0x7fc3908a, 0x8bef464e, 216}, + {0x97edd871, 0xcfda3a56, 0x97758bf0, 220}, + {0xbde94e8e, 0x43d0c8ec, 0x3d52eeed, 223}, + {0xed63a231, 0xd4c4fb27, 0x4ca7aaa8, 226}, + {0x945e455f, 0x24fb1cf8, 0x8fe8caa9, 230}, + {0xb975d6b6, 0xee39e436, 0xb3e2fd53, 233}, + {0xe7d34c64, 0xa9c85d44, 0x60dbbca8, 236}, + {0x90e40fbe, 0xea1d3a4a, 0xbc8955e9, 240}, + {0xb51d13ae, 0xa4a488dd, 0x6babab63, 243}, + {0xe264589a, 0x4dcdab14, 0xc696963c, 246}, + {0x8d7eb760, 0x70a08aec, 0xfc1e1de5, 250}, + {0xb0de6538, 0x8cc8ada8, 0x3b25a55f, 253}, + {0xdd15fe86, 0xaffad912, 0x49ef0eb7, 256}, + {0x8a2dbf14, 0x2dfcc7ab, 0x6e356932, 260}, + {0xacb92ed9, 0x397bf996, 0x49c2c37f, 263}, + {0xd7e77a8f, 0x87daf7fb, 0xdc33745e, 266}, + {0x86f0ac99, 0xb4e8dafd, 0x69a028bb, 270}, + {0xa8acd7c0, 0x222311bc, 0xc40832ea, 273}, + {0xd2d80db0, 0x2aabd62b, 0xf50a3fa4, 276}, + {0x83c7088e, 0x1aab65db, 0x792667c6, 280}, + {0xa4b8cab1, 0xa1563f52, 0x577001b8, 283}, + {0xcde6fd5e, 0x09abcf26, 0xed4c0226, 286}, + {0x80b05e5a, 0xc60b6178, 0x544f8158, 290}, + {0xa0dc75f1, 0x778e39d6, 0x696361ae, 293}, + {0xc913936d, 0xd571c84c, 0x03bc3a19, 296}, + {0xfb587849, 0x4ace3a5f, 0x04ab48a0, 299}, + {0x9d174b2d, 0xcec0e47b, 0x62eb0d64, 303}, + {0xc45d1df9, 0x42711d9a, 0x3ba5d0bd, 306}, + {0xf5746577, 0x930d6500, 0xca8f44ec, 309}, + {0x9968bf6a, 0xbbe85f20, 0x7e998b13, 313}, + {0xbfc2ef45, 0x6ae276e8, 0x9e3fedd8, 316}, + {0xefb3ab16, 0xc59b14a2, 0xc5cfe94e, 319}, + {0x95d04aee, 0x3b80ece5, 0xbba1f1d1, 323}, + {0xbb445da9, 0xca61281f, 0x2a8a6e45, 326}, + {0xea157514, 0x3cf97226, 0xf52d09d7, 329}, + {0x924d692c, 0xa61be758, 0x593c2626, 333}, + {0xb6e0c377, 0xcfa2e12e, 0x6f8b2fb0, 336}, + {0xe498f455, 0xc38b997a, 0x0b6dfb9c, 339}, + {0x8edf98b5, 0x9a373fec, 0x4724bd41, 343}, + {0xb2977ee3, 0x00c50fe7, 0x58edec91, 346}, + {0xdf3d5e9b, 0xc0f653e1, 0x2f2967b6, 349}, + {0x8b865b21, 0x5899f46c, 0xbd79e0d2, 353}, + {0xae67f1e9, 0xaec07187, 0xecd85906, 356}, + {0xda01ee64, 0x1a708de9, 0xe80e6f48, 359}, + {0x884134fe, 0x908658b2, 0x3109058d, 363}, + {0xaa51823e, 0x34a7eede, 0xbd4b46f0, 366}, + {0xd4e5e2cd, 0xc1d1ea96, 0x6c9e18ac, 369}, + {0x850fadc0, 0x9923329e, 0x03e2cf6b, 373}, + {0xa6539930, 0xbf6bff45, 0x84db8346, 376}, + {0xcfe87f7c, 0xef46ff16, 0xe6126418, 379}, + {0x81f14fae, 0x158c5f6e, 0x4fcb7e8f, 383}, + {0xa26da399, 0x9aef7749, 0xe3be5e33, 386}, + {0xcb090c80, 0x01ab551c, 0x5cadf5bf, 389}, + {0xfdcb4fa0, 0x02162a63, 0x73d9732f, 392}, + {0x9e9f11c4, 0x014dda7e, 0x2867e7fd, 396}, + {0xc646d635, 0x01a1511d, 0xb281e1fd, 399}, + {0xf7d88bc2, 0x4209a565, 0x1f225a7c, 402}, + {0x9ae75759, 0x6946075f, 0x3375788d, 406}, + {0xc1a12d2f, 0xc3978937, 0x0052d6b1, 409}, + {0xf209787b, 0xb47d6b84, 0xc0678c5d, 412}, + {0x9745eb4d, 0x50ce6332, 0xf840b7ba, 416}, + {0xbd176620, 0xa501fbff, 0xb650e5a9, 419}, + {0xec5d3fa8, 0xce427aff, 0xa3e51f13, 422}, + {0x93ba47c9, 0x80e98cdf, 0xc66f336c, 426}, + {0xb8a8d9bb, 0xe123f017, 0xb80b0047, 429}, + {0xe6d3102a, 0xd96cec1d, 0xa60dc059, 432}, + {0x9043ea1a, 0xc7e41392, 0x87c89837, 436}, + {0xb454e4a1, 0x79dd1877, 0x29babe45, 439}, + {0xe16a1dc9, 0xd8545e94, 0xf4296dd6, 442}, + {0x8ce2529e, 0x2734bb1d, 0x1899e4a6, 446}, + {0xb01ae745, 0xb101e9e4, 0x5ec05dcf, 449}, + {0xdc21a117, 0x1d42645d, 0x76707543, 452}, + {0x899504ae, 0x72497eba, 0x6a06494a, 456}, + {0xabfa45da, 0x0edbde69, 0x0487db9d, 459}, + {0xd6f8d750, 0x9292d603, 0x45a9d284, 462}, + {0x865b8692, 0x5b9bc5c2, 0x0b8a2392, 466}, + {0xa7f26836, 0xf282b732, 0x8e6cac77, 469}, + {0xd1ef0244, 0xaf2364ff, 0x3207d795, 472}, + {0x8335616a, 0xed761f1f, 0x7f44e6bd, 476}, + {0xa402b9c5, 0xa8d3a6e7, 0x5f16206c, 479}, + {0xcd036837, 0x130890a1, 0x36dba887, 482}, + {0x80222122, 0x6be55a64, 0xc2494954, 486}, + {0xa02aa96b, 0x06deb0fd, 0xf2db9baa, 489}, + {0xc83553c5, 0xc8965d3d, 0x6f928294, 492}, + {0xfa42a8b7, 0x3abbf48c, 0xcb772339, 495}, + {0x9c69a972, 0x84b578d7, 0xff2a7604, 499}, + {0xc38413cf, 0x25e2d70d, 0xfef51385, 502}, + {0xf46518c2, 0xef5b8cd1, 0x7eb25866, 505}, + {0x98bf2f79, 0xd5993802, 0xef2f773f, 509}, + {0xbeeefb58, 0x4aff8603, 0xaafb550f, 512}, + {0xeeaaba2e, 0x5dbf6784, 0x95ba2a53, 515}, + {0x952ab45c, 0xfa97a0b2, 0xdd945a74, 519}, + {0xba756174, 0x393d88df, 0x94f97111, 522}, + {0xe912b9d1, 0x478ceb17, 0x7a37cd56, 525}, + {0x91abb422, 0xccb812ee, 0xac62e055, 529}, + {0xb616a12b, 0x7fe617aa, 0x577b986b, 532}, + {0xe39c4976, 0x5fdf9d94, 0xed5a7e85, 535}, + {0x8e41ade9, 0xfbebc27d, 0x14588f13, 539}, + {0xb1d21964, 0x7ae6b31c, 0x596eb2d8, 542}, + {0xde469fbd, 0x99a05fe3, 0x6fca5f8e, 545}, + {0x8aec23d6, 0x80043bee, 0x25de7bb9, 549}, + {0xada72ccc, 0x20054ae9, 0xaf561aa7, 552}, + {0xd910f7ff, 0x28069da4, 0x1b2ba151, 555}, + {0x87aa9aff, 0x79042286, 0x90fb44d2, 559}, + {0xa99541bf, 0x57452b28, 0x353a1607, 562}, + {0xd3fa922f, 0x2d1675f2, 0x42889b89, 565}, + {0x847c9b5d, 0x7c2e09b7, 0x69956135, 569}, + {0xa59bc234, 0xdb398c25, 0x43fab983, 572}, + {0xcf02b2c2, 0x1207ef2e, 0x94f967e4, 575}, + {0x8161afb9, 0x4b44f57d, 0x1d1be0ee, 579}, + {0xa1ba1ba7, 0x9e1632dc, 0x6462d92a, 582}, + {0xca28a291, 0x859bbf93, 0x7d7b8f75, 585}, + {0xfcb2cb35, 0xe702af78, 0x5cda7352, 588}, + {0x9defbf01, 0xb061adab, 0x3a088813, 592}, + {0xc56baec2, 0x1c7a1916, 0x088aaa18, 595}, + {0xf6c69a72, 0xa3989f5b, 0x8aad549e, 598}, + {0x9a3c2087, 0xa63f6399, 0x36ac54e2, 602}, + {0xc0cb28a9, 0x8fcf3c7f, 0x84576a1b, 605}, + {0xf0fdf2d3, 0xf3c30b9f, 0x656d44a2, 608}, + {0x969eb7c4, 0x7859e743, 0x9f644ae5, 612}, + {0xbc4665b5, 0x96706114, 0x873d5d9f, 615}, + {0xeb57ff22, 0xfc0c7959, 0xa90cb506, 618}, + {0x9316ff75, 0xdd87cbd8, 0x09a7f124, 622}, + {0xb7dcbf53, 0x54e9bece, 0x0c11ed6d, 625}, + {0xe5d3ef28, 0x2a242e81, 0x8f1668c8, 628}, + {0x8fa47579, 0x1a569d10, 0xf96e017d, 632}, + {0xb38d92d7, 0x60ec4455, 0x37c981dc, 635}, + {0xe070f78d, 0x3927556a, 0x85bbe253, 638}, + {0x8c469ab8, 0x43b89562, 0x93956d74, 642}, + {0xaf584166, 0x54a6babb, 0x387ac8d1, 645}, + {0xdb2e51bf, 0xe9d0696a, 0x06997b05, 648}, + {0x88fcf317, 0xf22241e2, 0x441fece3, 652}, + {0xab3c2fdd, 0xeeaad25a, 0xd527e81c, 655}, + {0xd60b3bd5, 0x6a5586f1, 0x8a71e223, 658}, + {0x85c70565, 0x62757456, 0xf6872d56, 662}, + {0xa738c6be, 0xbb12d16c, 0xb428f8ac, 665}, + {0xd106f86e, 0x69d785c7, 0xe13336d7, 668}, + {0x82a45b45, 0x0226b39c, 0xecc00246, 672}, + {0xa34d7216, 0x42b06084, 0x27f002d7, 675}, + {0xcc20ce9b, 0xd35c78a5, 0x31ec038d, 678}, + {0xff290242, 0xc83396ce, 0x7e670471, 681}, + {0x9f79a169, 0xbd203e41, 0x0f0062c6, 685}, + {0xc75809c4, 0x2c684dd1, 0x52c07b78, 688}, + {0xf92e0c35, 0x37826145, 0xa7709a56, 691}, + {0x9bbcc7a1, 0x42b17ccb, 0x88a66076, 695}, + {0xc2abf989, 0x935ddbfe, 0x6acff893, 698}, + {0xf356f7eb, 0xf83552fe, 0x0583f6b8, 701}, + {0x98165af3, 0x7b2153de, 0xc3727a33, 705}, + {0xbe1bf1b0, 0x59e9a8d6, 0x744f18c0, 708}, + {0xeda2ee1c, 0x7064130c, 0x1162def0, 711}, + {0x9485d4d1, 0xc63e8be7, 0x8addcb56, 715}, + {0xb9a74a06, 0x37ce2ee1, 0x6d953e2b, 718}, + {0xe8111c87, 0xc5c1ba99, 0xc8fa8db6, 721}, + {0x910ab1d4, 0xdb9914a0, 0x1d9c9892, 725}, + {0xb54d5e4a, 0x127f59c8, 0x2503beb6, 728}, + {0xe2a0b5dc, 0x971f303a, 0x2e44ae64, 731}, + {0x8da471a9, 0xde737e24, 0x5ceaecfe, 735}, + {0xb10d8e14, 0x56105dad, 0x7425a83e, 738}, + {0xdd50f199, 0x6b947518, 0xd12f124e, 741}, + {0x8a5296ff, 0xe33cc92f, 0x82bd6b70, 745}, + {0xace73cbf, 0xdc0bfb7b, 0x636cc64d, 748}, + {0xd8210bef, 0xd30efa5a, 0x3c47f7e0, 751}, + {0x8714a775, 0xe3e95c78, 0x65acfaec, 755}, + {0xa8d9d153, 0x5ce3b396, 0x7f1839a7, 758}, + {0xd31045a8, 0x341ca07c, 0x1ede4811, 761}, + {0x83ea2b89, 0x2091e44d, 0x934aed0a, 765}, + {0xa4e4b66b, 0x68b65d60, 0xf81da84d, 768}, + {0xce1de406, 0x42e3f4b9, 0x36251260, 771}, + {0x80d2ae83, 0xe9ce78f3, 0xc1d72b7c, 775}, + {0xa1075a24, 0xe4421730, 0xb24cf65b, 778}, + {0xc94930ae, 0x1d529cfc, 0xdee033f2, 781}, + {0xfb9b7cd9, 0xa4a7443c, 0x169840ef, 784}, + {0x9d412e08, 0x06e88aa5, 0x8e1f2895, 788}, + {0xc491798a, 0x08a2ad4e, 0xf1a6f2ba, 791}, + {0xf5b5d7ec, 0x8acb58a2, 0xae10af69, 794}, + {0x9991a6f3, 0xd6bf1765, 0xacca6da1, 798}, + {0xbff610b0, 0xcc6edd3f, 0x17fd090a, 801}, + {0xeff394dc, 0xff8a948e, 0xddfc4b4c, 804}, + {0x95f83d0a, 0x1fb69cd9, 0x4abdaf10, 808}, + {0xbb764c4c, 0xa7a4440f, 0x9d6d1ad4, 811}, + {0xea53df5f, 0xd18d5513, 0x84c86189, 814}, + {0x92746b9b, 0xe2f8552c, 0x32fd3cf5, 818}, + {0xb7118682, 0xdbb66a77, 0x3fbc8c33, 821}, + {0xe4d5e823, 0x92a40515, 0x0fabaf3f, 824}, + {0x8f05b116, 0x3ba6832d, 0x29cb4d87, 828}, + {0xb2c71d5b, 0xca9023f8, 0x743e20e9, 831}, + {0xdf78e4b2, 0xbd342cf6, 0x914da924, 834}, + {0x8bab8eef, 0xb6409c1a, 0x1ad089b6, 838}, + {0xae9672ab, 0xa3d0c320, 0xa184ac24, 841}, + {0xda3c0f56, 0x8cc4f3e8, 0xc9e5d72d, 844}, + {0x88658996, 0x17fb1871, 0x7e2fa67c, 848}, + {0xaa7eebfb, 0x9df9de8d, 0xddbb901b, 851}, + {0xd51ea6fa, 0x85785631, 0x552a7422, 854}, + {0x8533285c, 0x936b35de, 0xd53a8895, 858}, + {0xa67ff273, 0xb8460356, 0x8a892aba, 861}, + {0xd01fef10, 0xa657842c, 0x2d2b7569, 864}, + {0x8213f56a, 0x67f6b29b, 0x9c3b2962, 868}, + {0xa298f2c5, 0x01f45f42, 0x8349f3ba, 871}, + {0xcb3f2f76, 0x42717713, 0x241c70a9, 874}, + {0xfe0efb53, 0xd30dd4d7, 0xed238cd3, 877}, + {0x9ec95d14, 0x63e8a506, 0xf4363804, 881}, + {0xc67bb459, 0x7ce2ce48, 0xb143c605, 884}, + {0xf81aa16f, 0xdc1b81da, 0xdd94b786, 887}, + {0x9b10a4e5, 0xe9913128, 0xca7cf2b4, 891}, + {0xc1d4ce1f, 0x63f57d72, 0xfd1c2f61, 894}, + {0xf24a01a7, 0x3cf2dccf, 0xbc633b39, 897}, + {0x976e4108, 0x8617ca01, 0xd5be0503, 901}, + {0xbd49d14a, 0xa79dbc82, 0x4b2d8644, 904}, + {0xec9c459d, 0x51852ba2, 0xddf8e7d6, 907}, + {0x93e1ab82, 0x52f33b45, 0xcabb90e5, 911}, + {0xb8da1662, 0xe7b00a17, 0x3d6a751f, 914}, + {0xe7109bfb, 0xa19c0c9d, 0x0cc51267, 917}, + {0x906a617d, 0x450187e2, 0x27fb2b80, 921}, + {0xb484f9dc, 0x9641e9da, 0xb1f9f660, 924}, + {0xe1a63853, 0xbbd26451, 0x5e7873f8, 927}, + {0x8d07e334, 0x55637eb2, 0xdb0b487b, 931}, + {0xb049dc01, 0x6abc5e5f, 0x91ce1a9a, 934}, + {0xdc5c5301, 0xc56b75f7, 0x7641a140, 937}, + {0x89b9b3e1, 0x1b6329ba, 0xa9e904c8, 941}, + {0xac2820d9, 0x623bf429, 0x546345fa, 944}, + {0xd732290f, 0xbacaf133, 0xa97c1779, 947}, + {0x867f59a9, 0xd4bed6c0, 0x49ed8eab, 951}, + {0xa81f3014, 0x49ee8c70, 0x5c68f256, 954}, + {0xd226fc19, 0x5c6a2f8c, 0x73832eec, 957}, + {0x83585d8f, 0xd9c25db7, 0xc831fd53, 961}, + {0xa42e74f3, 0xd032f525, 0xba3e7ca8, 964}, + {0xcd3a1230, 0xc43fb26f, 0x28ce1bd2, 967}, + {0x80444b5e, 0x7aa7cf85, 0x7980d163, 971}, + {0xa0555e36, 0x1951c366, 0xd7e105bc, 974}, + {0xc86ab5c3, 0x9fa63440, 0x8dd9472b, 977}, + {0xfa856334, 0x878fc150, 0xb14f98f6, 980}, + {0x9c935e00, 0xd4b9d8d2, 0x6ed1bf9a, 984}, + {0xc3b83581, 0x09e84f07, 0x0a862f80, 987}, + {0xf4a642e1, 0x4c6262c8, 0xcd27bb61, 990}, + {0x98e7e9cc, 0xcfbd7dbd, 0x8038d51c, 994}, + {0xbf21e440, 0x03acdd2c, 0xe0470a63, 997}, + {0xeeea5d50, 0x04981478, 0x1858ccfc, 1000}, + {0x95527a52, 0x02df0ccb, 0x0f37801e, 1004}, + {0xbaa718e6, 0x8396cffd, 0xd3056025, 1007}, + {0xe950df20, 0x247c83fd, 0x47c6b82e, 1010}, + {0x91d28b74, 0x16cdd27e, 0x4cdc331d, 1014}, + {0xb6472e51, 0x1c81471d, 0xe0133fe4, 1017}, + {0xe3d8f9e5, 0x63a198e5, 0x58180fdd, 1020}, + {0x8e679c2f, 0x5e44ff8f, 0x570f09ea, 1024}, + {0xb201833b, 0x35d63f73, 0x2cd2cc65, 1027}, + {0xde81e40a, 0x034bcf4f, 0xf8077f7e, 1030}, + {0x8b112e86, 0x420f6191, 0xfb04afaf, 1034}, + {0xadd57a27, 0xd29339f6, 0x79c5db9a, 1037}, + {0xd94ad8b1, 0xc7380874, 0x18375281, 1040}, + {0x87cec76f, 0x1c830548, 0x8f229391, 1044}, + {0xa9c2794a, 0xe3a3c69a, 0xb2eb3875, 1047}, + {0xd433179d, 0x9c8cb841, 0x5fa60692, 1050}, + {0x849feec2, 0x81d7f328, 0xdbc7c41b, 1054}, + {0xa5c7ea73, 0x224deff3, 0x12b9b522, 1057}, + {0xcf39e50f, 0xeae16bef, 0xd768226b, 1060}, + {0x81842f29, 0xf2cce375, 0xe6a11583, 1064}, + {0xa1e53af4, 0x6f801c53, 0x60495ae3, 1067}, + {0xca5e89b1, 0x8b602368, 0x385bb19c, 1070}, + {0xfcf62c1d, 0xee382c42, 0x46729e03, 1073}, + {0x9e19db92, 0xb4e31ba9, 0x6c07a2c2, 1077}}; +static const short int kDtoaLhint[2098] = { + /*18,*/ 19, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, + 22, 23, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, + 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, + 29, 30, 30, 30, 31, 31, 31, 32, 32, 32, 32, 33, + 33, 33, 34, 34, 34, 35, 35, 35, 35, 36, 36, 36, + 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 40, 40, + 40, 41, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, + 44, 44, 44, 45, 45, 45, 46, 46, 46, 47, 47, 47, + 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, + 51, 51, 52, 52, 52, 53, 53, 53, 54, 54, 54, 54, + 55, 55, 55, 56, 56, 56, 57, 57, 57, 57, 58, 58, + 58, 59, 59, 59, 60, 60, 60, 60, 61, 61, 61, 62, + 62, 62, 63, 63, 63, 63, 64, 64, 64, 65, 65, 65, + 66, 66, 66, 66, 67, 67, 67, 68, 68, 68, 69, 69, + 69, 69, 70, 70, 70, 71, 71, 71, 72, 72, 72, 72, + 73, 73, 73, 74, 74, 74, 75, 75, 75, 75, 76, 76, + 76, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 80, + 80, 80, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83, + 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 87, 87, + 87, 88, 88, 88, 88, 89, 89, 89, 90, 90, 90, 91, + 91, 91, 91, 92, 92, 92, 93, 93, 93, 94, 94, 94, + 94, 95, 95, 95, 96, 96, 96, 97, 97, 97, 97, 98, + 98, 98, 99, 99, 99, 100, 100, 100, 100, 101, 101, 101, + 102, 102, 102, 103, 103, 103, 103, 104, 104, 104, 105, 105, + 105, 106, 106, 106, 106, 107, 107, 107, 108, 108, 108, 109, + 109, 109, 110, 110, 110, 110, 111, 111, 111, 112, 112, 112, + 113, 113, 113, 113, 114, 114, 114, 115, 115, 115, 116, 116, + 116, 116, 117, 117, 117, 118, 118, 118, 119, 119, 119, 119, + 120, 120, 120, 121, 121, 121, 122, 122, 122, 122, 123, 123, + 123, 124, 124, 124, 125, 125, 125, 125, 126, 126, 126, 127, + 127, 127, 128, 128, 128, 128, 129, 129, 129, 130, 130, 130, + 131, 131, 131, 131, 132, 132, 132, 133, 133, 133, 134, 134, + 134, 134, 135, 135, 135, 136, 136, 136, 137, 137, 137, 137, + 138, 138, 138, 139, 139, 139, 140, 140, 140, 141, 141, 141, + 141, 142, 142, 142, 143, 143, 143, 144, 144, 144, 144, 145, + 145, 145, 146, 146, 146, 147, 147, 147, 147, 148, 148, 148, + 149, 149, 149, 150, 150, 150, 150, 151, 151, 151, 152, 152, + 152, 153, 153, 153, 153, 154, 154, 154, 155, 155, 155, 156, + 156, 156, 156, 157, 157, 157, 158, 158, 158, 159, 159, 159, + 159, 160, 160, 160, 161, 161, 161, 162, 162, 162, 162, 163, + 163, 163, 164, 164, 164, 165, 165, 165, 165, 166, 166, 166, + 167, 167, 167, 168, 168, 168, 169, 169, 169, 169, 170, 170, + 170, 171, 171, 171, 172, 172, 172, 172, 173, 173, 173, 174, + 174, 174, 175, 175, 175, 175, 176, 176, 176, 177, 177, 177, + 178, 178, 178, 178, 179, 179, 179, 180, 180, 180, 181, 181, + 181, 181, 182, 182, 182, 183, 183, 183, 184, 184, 184, 184, + 185, 185, 185, 186, 186, 186, 187, 187, 187, 187, 188, 188, + 188, 189, 189, 189, 190, 190, 190, 190, 191, 191, 191, 192, + 192, 192, 193, 193, 193, 193, 194, 194, 194, 195, 195, 195, + 196, 196, 196, 197, 197, 197, 197, 198, 198, 198, 199, 199, + 199, 200, 200, 200, 200, 201, 201, 201, 202, 202, 202, 203, + 203, 203, 203, 204, 204, 204, 205, 205, 205, 206, 206, 206, + 206, 207, 207, 207, 208, 208, 208, 209, 209, 209, 209, 210, + 210, 210, 211, 211, 211, 212, 212, 212, 212, 213, 213, 213, + 214, 214, 214, 215, 215, 215, 215, 216, 216, 216, 217, 217, + 217, 218, 218, 218, 218, 219, 219, 219, 220, 220, 220, 221, + 221, 221, 221, 222, 222, 222, 223, 223, 223, 224, 224, 224, + 224, 225, 225, 225, 226, 226, 226, 227, 227, 227, 228, 228, + 228, 228, 229, 229, 229, 230, 230, 230, 231, 231, 231, 231, + 232, 232, 232, 233, 233, 233, 234, 234, 234, 234, 235, 235, + 235, 236, 236, 236, 237, 237, 237, 237, 238, 238, 238, 239, + 239, 239, 240, 240, 240, 240, 241, 241, 241, 242, 242, 242, + 243, 243, 243, 243, 244, 244, 244, 245, 245, 245, 246, 246, + 246, 246, 247, 247, 247, 248, 248, 248, 249, 249, 249, 249, + 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, + 253, 254, 254, 254, 255, 255, 255, 256, 256, 256, 256, 257, + 257, 257, 258, 258, 258, 259, 259, 259, 259, 260, 260, 260, + 261, 261, 261, 262, 262, 262, 262, 263, 263, 263, 264, 264, + 264, 265, 265, 265, 265, 266, 266, 266, 267, 267, 267, 268, + 268, 268, 268, 269, 269, 269, 270, 270, 270, 271, 271, 271, + 271, 272, 272, 272, 273, 273, 273, 274, 274, 274, 274, 275, + 275, 275, 276, 276, 276, 277, 277, 277, 277, 278, 278, 278, + 279, 279, 279, 280, 280, 280, 280, 281, 281, 281, 282, 282, + 282, 283, 283, 283, 283, 284, 284, 284, 285, 285, 285, 286, + 286, 286, 287, 287, 287, 287, 288, 288, 288, 289, 289, 289, + 290, 290, 290, 290, 291, 291, 291, 292, 292, 292, 293, 293, + 293, 293, 294, 294, 294, 295, 295, 295, 296, 296, 296, 296, + 297, 297, 297, 298, 298, 298, 299, 299, 299, 299, 300, 300, + 300, 301, 301, 301, 302, 302, 302, 302, 303, 303, 303, 304, + 304, 304, 305, 305, 305, 305, 306, 306, 306, 307, 307, 307, + 308, 308, 308, 308, 309, 309, 309, 310, 310, 310, 311, 311, + 311, 311, 312, 312, 312, 313, 313, 313, 314, 314, 314, 315, + 315, 315, 315, 316, 316, 316, 317, 317, 317, 318, 318, 318, + 318, 319, 319, 319, 320, 320, 320, 321, 321, 321, 321, 322, + 322, 322, 323, 323, 323, 324, 324, 324, 324, 325, 325, 325, + 326, 326, 326, 327, 327, 327, 327, 328, 328, 328, 329, 329, + 329, 330, 330, 330, 330, 331, 331, 331, 332, 332, 332, 333, + 333, 333, 333, 334, 334, 334, 335, 335, 335, 336, 336, 336, + 336, 337, 337, 337, 338, 338, 338, 339, 339, 339, 339, 340, + 340, 340, 341, 341, 341, 342, 342, 342, 342, 343, 343, 343, + 344, 344, 344, 345, 345, 345, 346, 346, 346, 346, 347, 347, + 347, 348, 348, 348, 349, 349, 349, 349, 350, 350, 350, 351, + 351, 351, 352, 352, 352, 352, 353, 353, 353, 354, 354, 354, + 355, 355, 355, 355, 356, 356, 356, 357, 357, 357, 358, 358, + 358, 358, 359, 359, 359, 360, 360, 360, 361, 361, 361, 361, + 362, 362, 362, 363, 363, 363, 364, 364, 364, 364, 365, 365, + 365, 366, 366, 366, 367, 367, 367, 367, 368, 368, 368, 369, + 369, 369, 370, 370, 370, 370, 371, 371, 371, 372, 372, 372, + 373, 373, 373, 374, 374, 374, 374, 375, 375, 375, 376, 376, + 376, 377, 377, 377, 377, 378, 378, 378, 379, 379, 379, 380, + 380, 380, 380, 381, 381, 381, 382, 382, 382, 383, 383, 383, + 383, 384, 384, 384, 385, 385, 385, 386, 386, 386, 386, 387, + 387, 387, 388, 388, 388, 389, 389, 389, 389, 390, 390, 390, + 391, 391, 391, 392, 392, 392, 392, 393, 393, 393, 394, 394, + 394, 395, 395, 395, 395, 396, 396, 396, 397, 397, 397, 398, + 398, 398, 398, 399, 399, 399, 400, 400, 400, 401, 401, 401, + 402, 402, 402, 402, 403, 403, 403, 404, 404, 404, 405, 405, + 405, 405, 406, 406, 406, 407, 407, 407, 408, 408, 408, 408, + 409, 409, 409, 410, 410, 410, 411, 411, 411, 411, 412, 412, + 412, 413, 413, 413, 414, 414, 414, 414, 415, 415, 415, 416, + 416, 416, 417, 417, 417, 417, 418, 418, 418, 419, 419, 419, + 420, 420, 420, 420, 421, 421, 421, 422, 422, 422, 423, 423, + 423, 423, 424, 424, 424, 425, 425, 425, 426, 426, 426, 426, + 427, 427, 427, 428, 428, 428, 429, 429, 429, 429, 430, 430, + 430, 431, 431, 431, 432, 432, 432, 433, 433, 433, 433, 434, + 434, 434, 435, 435, 435, 436, 436, 436, 436, 437, 437, 437, + 438, 438, 438, 439, 439, 439, 439, 440, 440, 440, 441, 441, + 441, 442, 442, 442, 442, 443, 443, 443, 444, 444, 444, 445, + 445, 445, 445, 446, 446, 446, 447, 447, 447, 448, 448, 448, + 448, 449, 449, 449, 450, 450, 450, 451, 451, 451, 451, 452, + 452, 452, 453, 453, 453, 454, 454, 454, 454, 455, 455, 455, + 456, 456, 456, 457, 457, 457, 457, 458, 458, 458, 459, 459, + 459, 460, 460, 460, 461, 461, 461, 461, 462, 462, 462, 463, + 463, 463, 464, 464, 464, 464, 465, 465, 465, 466, 466, 466, + 467, 467, 467, 467, 468, 468, 468, 469, 469, 469, 470, 470, + 470, 470, 471, 471, 471, 472, 472, 472, 473, 473, 473, 473, + 474, 474, 474, 475, 475, 475, 476, 476, 476, 476, 477, 477, + 477, 478, 478, 478, 479, 479, 479, 479, 480, 480, 480, 481, + 481, 481, 482, 482, 482, 482, 483, 483, 483, 484, 484, 484, + 485, 485, 485, 485, 486, 486, 486, 487, 487, 487, 488, 488, + 488, 488, 489, 489, 489, 490, 490, 490, 491, 491, 491, 492, + 492, 492, 492, 493, 493, 493, 494, 494, 494, 495, 495, 495, + 495, 496, 496, 496, 497, 497, 497, 498, 498, 498, 498, 499, + 499, 499, 500, 500, 500, 501, 501, 501, 501, 502, 502, 502, + 503, 503, 503, 504, 504, 504, 504, 505, 505, 505, 506, 506, + 506, 507, 507, 507, 507, 508, 508, 508, 509, 509, 509, 510, + 510, 510, 510, 511, 511, 511, 512, 512, 512, 513, 513, 513, + 513, 514, 514, 514, 515, 515, 515, 516, 516, 516, 516, 517, + 517, 517, 518, 518, 518, 519, 519, 519, 520, 520, 520, 520, + 521, 521, 521, 522, 522, 522, 523, 523, 523, 523, 524, 524, + 524, 525, 525, 525, 526, 526, 526, 526, 527, 527, 527, 528, + 528, 528, 529, 529, 529, 529, 530, 530, 530, 531, 531, 531, + 532, 532, 532, 532, 533, 533, 533, 534, 534, 534, 535, 535, + 535, 535, 536, 536, 536, 537, 537, 537, 538, 538, 538, 538, + 539, 539, 539, 540, 540, 540, 541, 541, 541, 541, 542, 542, + 542, 543, 543, 543, 544, 544, 544, 544, 545, 545, 545, 546, + 546, 546, 547, 547, 547, 548, 548, 548, 548, 549, 549, 549, + 550, 550, 550, 551, 551, 551, 551, 552, 552, 552, 553, 553, + 553, 554, 554, 554, 554, 555, 555, 555, 556, 556, 556, 557, + 557, 557, 557, 558, 558, 558, 559, 559, 559, 560, 560, 560, + 560, 561, 561, 561, 562, 562, 562, 563, 563, 563, 563, 564, + 564, 564, 565, 565, 565, 566, 566, 566, 566, 567, 567, 567, + 568, 568, 568, 569, 569, 569, 569, 570, 570, 570, 571, 571, + 571, 572, 572, 572, 572, 573, 573, 573, 574, 574, 574, 575, + 575, 575, 575, 576, 576, 576, 577, 577, 577, 578, 578, 578, + 579, 579, 579, 579, 580, 580, 580, 581, 581, 581, 582, 582, + 582, 582, 583, 583, 583, 584, 584, 584, 585, 585, 585, 585, + 586, 586, 586, 587, 587, 587, 588, 588, 588, 588, 589, 589, + 589, 590, 590, 590, 591, 591, 591, 591, 592, 592, 592, 593, + 593, 593, 594, 594, 594, 594, 595, 595, 595, 596, 596, 596, + 597, 597, 597, 597, 598, 598, 598, 599, 599, 599, 600, 600, + 600, 600, 601, 601, 601, 602, 602, 602, 603, 603, 603, 603, + 604, 604, 604, 605, 605, 605, 606, 606, 606, 607, 607, 607, + 607, 608, 608, 608, 609, 609, 609, 610, 610, 610, 610, 611, + 611, 611, 612, 612, 612, 613, 613, 613, 613, 614, 614, 614, + 615, 615, 615, 616, 616, 616, 616, 617, 617, 617, 618, 618, + 618, 619, 619, 619, 619, 620, 620, 620, 621, 621, 621, 622, + 622, 622, 622, 623, 623, 623, 624, 624, 624, 625, 625, 625, + 625, 626, 626, 626, 627, 627, 627, 628, 628, 628, 628, 629, + 629, 629, 630, 630, 630, 631, 631, 631, 631, 632, 632, 632, + 633, 633, 633, 634, 634, 634, 634, 635, 635, 635, 636, 636, + 636, 637, 637, 637, 638, 638, 638, 638, 639, 639, 639, 640, + 640, 640, 641, 641, 641, 641, 642, 642, 642, 643, 643, 643, + 644, 644, 644, 644, 645, 645, 645, 646, 646, 646, 647, 647, + 647, 647, 648, 648, 648, 649, 649, 649, 650, 650}; +static ULLong kDtoaPfive[27] = {5ll, + 25ll, + 125ll, + 625ll, + 3125ll, + 15625ll, + 78125ll, + 390625ll, + 1953125ll, + 9765625ll, + 48828125ll, + 244140625ll, + 1220703125ll, + 6103515625ll, + 30517578125ll, + 152587890625ll, + 762939453125ll, + 3814697265625ll, + 19073486328125ll, + 95367431640625ll, + 476837158203125ll, + 2384185791015625ll, + 11920928955078125ll, + 59604644775390625ll, + 298023223876953125ll, + 1490116119384765625ll, + 7450580596923828125ll}; - static int pfivebits[25] = {3, 5, 7, 10, 12, 14, 17, 19, 21, 24, 26, 28, 31, - 33, 35, 38, 40, 42, 45, 47, 49, 52, 54, 56, 59}; +static int kDtoaPfiveBits[25] = {3, 5, 7, 10, 12, 14, 17, 19, 21, + 24, 26, 28, 31, 33, 35, 38, 40, 42, + 45, 47, 49, 52, 54, 56, 59}; #endif /*}*/ #endif /*}} NO_LONG_LONG */ -typedef union { double d; ULong L[2]; + typedef union { + double d; + ULong L[2]; #ifdef USE_BF96 - ULLong LL; + ULLong LL; #endif - } U; +} U; #ifdef IEEE_8087 #define word0(x) (x)->L[1] @@ -1333,7 +1303,7 @@ typedef union { double d; ULong L[2]; #define word0(x) (x)->L[0] #define word1(x) (x)->L[1] #endif -#define dval(x) (x)->d +#define dval(x) (x)->d #define LLval(x) (x)->LL #ifndef STRTOD_DIGLIM @@ -1351,11 +1321,13 @@ extern int strtod_diglim; * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) */ #if defined(IEEE_8087) + defined(VAX) -#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ -((unsigned short *)a)[0] = (unsigned short)c, a++) +#define Storeinc(a, b, c) \ + (((unsigned short *)a)[1] = (unsigned short)b, \ + ((unsigned short *)a)[0] = (unsigned short)c, a++) #else -#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ -((unsigned short *)a)[1] = (unsigned short)c, a++) +#define Storeinc(a, b, c) \ + (((unsigned short *)a)[0] = (unsigned short)b, \ + ((unsigned short *)a)[1] = (unsigned short)c, a++) #endif /* #define P DBL_MANT_DIG */ @@ -1365,35 +1337,35 @@ extern int strtod_diglim; /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ #ifdef IEEE_Arith -#define Exp_shift 20 -#define Exp_shift1 20 +#define Exp_shift 20 +#define Exp_shift1 20 #define Exp_msk1 0x100000 #define Exp_msk11 0x100000 -#define Exp_mask 0x7ff00000 -#define P 53 -#define Nbits 53 -#define Bias 1023 -#define Emax 1023 -#define Emin (-1022) -#define Exp_1 0x3ff00000 -#define Exp_11 0x3ff00000 -#define Ebits 11 -#define Frac_mask 0xfffff -#define Frac_mask1 0xfffff -#define Ten_pmax 22 -#define Bletch 0x10 +#define Exp_mask 0x7ff00000 +#define P 53 +#define Nbits 53 +#define Bias 1023 +#define Emax 1023 +#define Emin (-1022) +#define Exp_1 0x3ff00000 +#define Exp_11 0x3ff00000 +#define Ebits 11 +#define Frac_mask 0xfffff +#define Frac_mask1 0xfffff +#define Ten_pmax 22 +#define Bletch 0x10 #define Bndry_mask 0xfffff #define Bndry_mask1 0xfffff -#define LSB 1 -#define Sign_bit 0x80000000 -#define Log2P 1 -#define Tiny0 0 -#define Tiny1 1 -#define Quick_max 14 -#define Int_max 14 +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 1 +#define Tiny0 0 +#define Tiny1 1 +#define Quick_max 14 +#define Int_max 14 #ifndef NO_IEEE_Scale #define Avoid_Underflow -#ifdef Flush_Denorm /* debugging option */ +#ifdef Flush_Denorm /* debugging option */ #undef Sudden_Underflow #endif #endif @@ -1417,66 +1389,66 @@ extern int strtod_diglim; #undef Check_FLT_ROUNDS #undef Honor_FLT_ROUNDS #undef SET_INEXACT -#undef Sudden_Underflow +#undef Sudden_Underflow #define Sudden_Underflow #ifdef IBM #undef Flt_Rounds -#define Flt_Rounds 0 -#define Exp_shift 24 -#define Exp_shift1 24 -#define Exp_msk1 0x1000000 -#define Exp_msk11 0x1000000 -#define Exp_mask 0x7f000000 -#define P 14 -#define Nbits 56 -#define Bias 65 -#define Emax 248 -#define Emin (-260) -#define Exp_1 0x41000000 -#define Exp_11 0x41000000 -#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ -#define Frac_mask 0xffffff -#define Frac_mask1 0xffffff -#define Bletch 4 -#define Ten_pmax 22 +#define Flt_Rounds 0 +#define Exp_shift 24 +#define Exp_shift1 24 +#define Exp_msk1 0x1000000 +#define Exp_msk11 0x1000000 +#define Exp_mask 0x7f000000 +#define P 14 +#define Nbits 56 +#define Bias 65 +#define Emax 248 +#define Emin (-260) +#define Exp_1 0x41000000 +#define Exp_11 0x41000000 +#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ +#define Frac_mask 0xffffff +#define Frac_mask1 0xffffff +#define Bletch 4 +#define Ten_pmax 22 #define Bndry_mask 0xefffff #define Bndry_mask1 0xffffff -#define LSB 1 -#define Sign_bit 0x80000000 -#define Log2P 4 -#define Tiny0 0x100000 -#define Tiny1 0 -#define Quick_max 14 -#define Int_max 15 +#define LSB 1 +#define Sign_bit 0x80000000 +#define Log2P 4 +#define Tiny0 0x100000 +#define Tiny1 0 +#define Quick_max 14 +#define Int_max 15 #else /* VAX */ #undef Flt_Rounds -#define Flt_Rounds 1 -#define Exp_shift 23 -#define Exp_shift1 7 +#define Flt_Rounds 1 +#define Exp_shift 23 +#define Exp_shift1 7 #define Exp_msk1 0x80 #define Exp_msk11 0x800000 -#define Exp_mask 0x7f80 -#define P 56 -#define Nbits 56 -#define Bias 129 -#define Emax 126 -#define Emin (-129) -#define Exp_1 0x40800000 -#define Exp_11 0x4080 -#define Ebits 8 -#define Frac_mask 0x7fffff -#define Frac_mask1 0xffff007f -#define Ten_pmax 24 -#define Bletch 2 +#define Exp_mask 0x7f80 +#define P 56 +#define Nbits 56 +#define Bias 129 +#define Emax 126 +#define Emin (-129) +#define Exp_1 0x40800000 +#define Exp_11 0x4080 +#define Ebits 8 +#define Frac_mask 0x7fffff +#define Frac_mask1 0xffff007f +#define Ten_pmax 24 +#define Bletch 2 #define Bndry_mask 0xffff007f #define Bndry_mask1 0xffff007f -#define LSB 0x10000 -#define Sign_bit 0x8000 -#define Log2P 1 -#define Tiny0 0x80 -#define Tiny1 0 -#define Quick_max 15 -#define Int_max 15 +#define LSB 0x10000 +#define Sign_bit 0x8000 +#define Log2P 1 +#define Tiny0 0x80 +#define Tiny1 0 +#define Quick_max 15 +#define Int_max 15 #endif /* IBM, VAX */ #endif /* IEEE_Arith */ @@ -1484,21 +1456,21 @@ extern int strtod_diglim; #define ROUND_BIASED #else #ifdef ROUND_BIASED_without_Round_Up -#undef ROUND_BIASED +#undef ROUND_BIASED #define ROUND_BIASED #endif #endif #ifdef RND_PRODQUOT -#define rounded_product(a,b) a = rnd_prod(a, b) -#define rounded_quotient(a,b) a = rnd_quot(a, b) +#define rounded_product(a, b) a = rnd_prod(a, b) +#define rounded_quotient(a, b) a = rnd_quot(a, b) extern double rnd_prod(double, double), rnd_quot(double, double); #else -#define rounded_product(a,b) a *= b -#define rounded_quotient(a,b) a /= b +#define rounded_product(a, b) a *= b +#define rounded_quotient(a, b) a /= b #endif -#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1)) +#define Big0 (Frac_mask1 | Exp_msk1 * (DBL_MAX_EXP + Bias - 1)) #define Big1 0xffffffff #ifndef Pack_32 @@ -1506,8 +1478,9 @@ extern double rnd_prod(double, double), rnd_quot(double, double); #endif typedef struct BCinfo BCinfo; - struct -BCinfo { int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflchk; }; +struct BCinfo { + int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflchk; +}; #define FFFFFFFF 0xffffffffUL @@ -1525,965 +1498,891 @@ static unsigned int maxthreads = 0; #define Kmax 7 #ifdef __cplusplus -extern "C" double (strtod)(const char *s00, char **se); -extern "C" char *dtoa(double d, int mode, int ndigits, - int *decpt, int *sign, char **rve); +extern "C" double(strtod)(const char *s00, char **se); +extern "C" char *dtoa(double d, int mode, int ndigits, int *decpt, int *sign, + char **rve); #endif - struct -Bigint { - struct Bigint *next; - int k, maxwds, sign, wds; - ULong x[1]; - }; +struct Bigint { + struct Bigint *next; + int k, maxwds, sign, wds; + ULong x[1]; +}; - typedef struct Bigint Bigint; - typedef struct -ThInfo { - Bigint *Freelist[Kmax+1]; - Bigint *P5s; - } ThInfo; +typedef struct Bigint Bigint; +typedef struct ThInfo { + Bigint *Freelist[Kmax + 1]; + Bigint *P5s; +} ThInfo; - static ThInfo TI0; +static ThInfo TI0; #ifdef MULTIPLE_THREADS - static ThInfo *TI1; - static int TI0_used; +static ThInfo *TI1; +static int TI0_used; - void -set_max_dtoa_threads(unsigned int n) -{ - size_t L; +void set_max_dtoa_threads(unsigned int n) { + size_t L; - if (n > maxthreads) { - L = n*sizeof(ThInfo); - if (TI1) { - TI1 = (ThInfo*)REALLOC(TI1, L); - memset(TI1 + maxthreads, 0, (n-maxthreads)*sizeof(ThInfo)); - } - else { - TI1 = (ThInfo*)MALLOC(L); - if (TI0_used) { - memcpy(TI1, &TI0, sizeof(ThInfo)); - if (n > 1) - memset(TI1 + 1, 0, L - sizeof(ThInfo)); - memset(&TI0, 0, sizeof(ThInfo)); - } - else - memset(TI1, 0, L); - } - maxthreads = n; - } - } + if (n > maxthreads) { + L = n * sizeof(ThInfo); + if (TI1) { + TI1 = (ThInfo *)REALLOC(TI1, L); + memset(TI1 + maxthreads, 0, (n - maxthreads) * sizeof(ThInfo)); + } else { + TI1 = (ThInfo *)MALLOC(L); + if (TI0_used) { + memcpy(TI1, &TI0, sizeof(ThInfo)); + if (n > 1) memset(TI1 + 1, 0, L - sizeof(ThInfo)); + memset(&TI0, 0, sizeof(ThInfo)); + } else + memset(TI1, 0, L); + } + maxthreads = n; + } +} - static ThInfo* -get_TI(void) -{ - unsigned int thno = dtoa_get_threadno(); - if (thno < maxthreads) - return TI1 + thno; - if (thno == 0) - TI0_used = 1; - return &TI0; - } +static ThInfo *get_TI(void) { + unsigned int thno = dtoa_get_threadno(); + if (thno < maxthreads) return TI1 + thno; + if (thno == 0) TI0_used = 1; + return &TI0; +} #define freelist TI->Freelist -#define p5s TI->P5s +#define p5s TI->P5s #else #define freelist TI0.Freelist -#define p5s TI0.P5s +#define p5s TI0.P5s #endif - static Bigint * -Balloc(int k MTd) -{ - int x; - Bigint *rv; +static Bigint *dtoa_balloc(int k MTd) { + int x; + Bigint *rv; #ifndef Omit_Private_Memory - unsigned int len; + unsigned int len; #endif #ifdef MULTIPLE_THREADS - ThInfo *TI; + ThInfo *TI; - if (!(TI = *PTI)) - *PTI = TI = get_TI(); - if (TI == &TI0) - ACQUIRE_DTOA_LOCK(0); + if (!(TI = *PTI)) *PTI = TI = get_TI(); + if (TI == &TI0) ACQUIRE_DTOA_LOCK(0); #endif - /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */ - /* but this case seems very unlikely. */ - if (k <= Kmax && (rv = freelist[k])) - freelist[k] = rv->next; - else { - x = 1u << k; + /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */ + /* but this case seems very unlikely. */ + if (k <= Kmax && (rv = freelist[k])) + freelist[k] = rv->next; + else { + x = 1u << k; #ifdef Omit_Private_Memory - rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong)); + rv = (Bigint *)MALLOC(sizeof(Bigint) + (x - 1) * sizeof(ULong)); #else - len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) - /sizeof(double); - if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem + len = (sizeof(Bigint) + (x - 1) * sizeof(ULong) + sizeof(double) - 1) / + sizeof(double); + if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem #ifdef MULTIPLE_THREADS - && TI == TI1 + && TI == TI1 #endif - ) { - rv = (Bigint*)pmem_next; - pmem_next += len; - } - else - rv = (Bigint*)MALLOC(len*sizeof(double)); + ) { + rv = (Bigint *)pmem_next; + pmem_next += len; + } else + rv = (Bigint *)MALLOC(len * sizeof(double)); #endif - rv->k = k; - rv->maxwds = x; - } + rv->k = k; + rv->maxwds = x; + } #ifdef MULTIPLE_THREADS - if (TI == &TI0) - FREE_DTOA_LOCK(0); + if (TI == &TI0) FREE_DTOA_LOCK(0); #endif - rv->sign = rv->wds = 0; - return rv; - } + rv->sign = rv->wds = 0; + return rv; +} - static void -Bfree(Bigint *v MTd) +static void dtoa_bfree(Bigint *v MTd) { +#ifdef MULTIPLE_THREADS + ThInfo *TI; +#endif + if (v) { + if (v->k > Kmax) + FREE((void *)v); + else { +#ifdef MULTIPLE_THREADS + if (!(TI = *PTI)) *PTI = TI = get_TI(); + if (TI == &TI0) ACQUIRE_DTOA_LOCK(0); +#endif + v->next = freelist[v->k]; + freelist[v->k] = v; +#ifdef MULTIPLE_THREADS + if (TI == &TI0) FREE_DTOA_LOCK(0); +#endif + } + } +} + +#define Bcopy(x, y) \ + memcpy((char *)&x->sign, (char *)&y->sign, \ + y->wds * sizeof(Long) + 2 * sizeof(int)) + +static Bigint *dtoa_multadd(Bigint *b, int m, + int a MTd) /* multiply by m and add a */ { -#ifdef MULTIPLE_THREADS - ThInfo *TI; -#endif - if (v) { - if (v->k > Kmax) - FREE((void*)v); - else { -#ifdef MULTIPLE_THREADS - if (!(TI = *PTI)) - *PTI = TI = get_TI(); - if (TI == &TI0) - ACQUIRE_DTOA_LOCK(0); -#endif - v->next = freelist[v->k]; - freelist[v->k] = v; -#ifdef MULTIPLE_THREADS - if (TI == &TI0) - FREE_DTOA_LOCK(0); -#endif - } - } - } - -#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ -y->wds*sizeof(Long) + 2*sizeof(int)) - - static Bigint * -multadd(Bigint *b, int m, int a MTd) /* multiply by m and add a */ -{ - int i, wds; + int i, wds; #ifdef ULLong - ULong *x; - ULLong carry, y; + ULong *x; + ULLong carry, y; #else - ULong carry, *x, y; + ULong carry, *x, y; #ifdef Pack_32 - ULong xi, z; + ULong xi, z; #endif #endif - Bigint *b1; + Bigint *b1; - wds = b->wds; - x = b->x; - i = 0; - carry = a; - do { + wds = b->wds; + x = b->x; + i = 0; + carry = a; + do { #ifdef ULLong - y = *x * (ULLong)m + carry; - carry = y >> 32; - *x++ = y & FFFFFFFF; + y = *x * (ULLong)m + carry; + carry = y >> 32; + *x++ = y & FFFFFFFF; #else #ifdef Pack_32 - xi = *x; - y = (xi & 0xffff) * m + carry; - z = (xi >> 16) * m + (y >> 16); - carry = z >> 16; - *x++ = (z << 16) + (y & 0xffff); + xi = *x; + y = (xi & 0xffff) * m + carry; + z = (xi >> 16) * m + (y >> 16); + carry = z >> 16; + *x++ = (z << 16) + (y & 0xffff); #else - y = *x * m + carry; - carry = y >> 16; - *x++ = y & 0xffff; + y = *x * m + carry; + carry = y >> 16; + *x++ = y & 0xffff; #endif #endif - } - while(++i < wds); - if (carry) { - if (wds >= b->maxwds) { - b1 = Balloc(b->k+1 MTa); - Bcopy(b1, b); - Bfree(b MTa); - b = b1; - } - b->x[wds++] = carry; - b->wds = wds; - } - return b; - } + } while (++i < wds); + if (carry) { + if (wds >= b->maxwds) { + b1 = dtoa_balloc(b->k + 1 MTa); + Bcopy(b1, b); + dtoa_bfree(b MTa); + b = b1; + } + b->x[wds++] = carry; + b->wds = wds; + } + return b; +} - static Bigint * -s2b(const char *s, int nd0, int nd, ULong y9, int dplen MTd) -{ - Bigint *b; - int i, k; - Long x, y; +static Bigint *s2b(const char *s, int nd0, int nd, ULong y9, int dplen MTd) { + Bigint *b; + int i, k; + Long x, y; - x = (nd + 8) / 9; - for(k = 0, y = 1; x > y; y <<= 1, k++) ; + x = (nd + 8) / 9; + for (k = 0, y = 1; x > y; y <<= 1, k++) + ; #ifdef Pack_32 - b = Balloc(k MTa); - b->x[0] = y9; - b->wds = 1; + b = dtoa_balloc(k MTa); + b->x[0] = y9; + b->wds = 1; #else - b = Balloc(k+1 MTa); - b->x[0] = y9 & 0xffff; - b->wds = (b->x[1] = y9 >> 16) ? 2 : 1; + b = dtoa_balloc(k + 1 MTa); + b->x[0] = y9 & 0xffff; + b->wds = (b->x[1] = y9 >> 16) ? 2 : 1; #endif - i = 9; - if (9 < nd0) { - s += 9; - do b = multadd(b, 10, *s++ - '0' MTa); - while(++i < nd0); - s += dplen; - } - else - s += dplen + 9; - for(; i < nd; i++) - b = multadd(b, 10, *s++ - '0' MTa); - return b; - } + i = 9; + if (9 < nd0) { + s += 9; + do + b = dtoa_multadd(b, 10, *s++ - '0' MTa); + while (++i < nd0); + s += dplen; + } else + s += dplen + 9; + for (; i < nd; i++) b = dtoa_multadd(b, 10, *s++ - '0' MTa); + return b; +} - static int -hi0bits(ULong x) -{ - int k = 0; +static int dtoa_hi0bits(ULong x) { + int k = 0; - if (!(x & 0xffff0000)) { - k = 16; - x <<= 16; - } - if (!(x & 0xff000000)) { - k += 8; - x <<= 8; - } - if (!(x & 0xf0000000)) { - k += 4; - x <<= 4; - } - if (!(x & 0xc0000000)) { - k += 2; - x <<= 2; - } - if (!(x & 0x80000000)) { - k++; - if (!(x & 0x40000000)) - return 32; - } - return k; - } + if (!(x & 0xffff0000)) { + k = 16; + x <<= 16; + } + if (!(x & 0xff000000)) { + k += 8; + x <<= 8; + } + if (!(x & 0xf0000000)) { + k += 4; + x <<= 4; + } + if (!(x & 0xc0000000)) { + k += 2; + x <<= 2; + } + if (!(x & 0x80000000)) { + k++; + if (!(x & 0x40000000)) return 32; + } + return k; +} - static int -lo0bits(ULong *y) -{ - int k; - ULong x = *y; +static int dtoa_lo0bits(ULong *y) { + int k; + ULong x = *y; - if (x & 7) { - if (x & 1) - return 0; - if (x & 2) { - *y = x >> 1; - return 1; - } - *y = x >> 2; - return 2; - } - k = 0; - if (!(x & 0xffff)) { - k = 16; - x >>= 16; - } - if (!(x & 0xff)) { - k += 8; - x >>= 8; - } - if (!(x & 0xf)) { - k += 4; - x >>= 4; - } - if (!(x & 0x3)) { - k += 2; - x >>= 2; - } - if (!(x & 1)) { - k++; - x >>= 1; - if (!x) - return 32; - } - *y = x; - return k; - } + if (x & 7) { + if (x & 1) return 0; + if (x & 2) { + *y = x >> 1; + return 1; + } + *y = x >> 2; + return 2; + } + k = 0; + if (!(x & 0xffff)) { + k = 16; + x >>= 16; + } + if (!(x & 0xff)) { + k += 8; + x >>= 8; + } + if (!(x & 0xf)) { + k += 4; + x >>= 4; + } + if (!(x & 0x3)) { + k += 2; + x >>= 2; + } + if (!(x & 1)) { + k++; + x >>= 1; + if (!x) return 32; + } + *y = x; + return k; +} - static Bigint * -i2b(int i MTd) -{ - Bigint *b; +static Bigint *dtoa_i2b(int i MTd) { + Bigint *b; - b = Balloc(1 MTa); - b->x[0] = i; - b->wds = 1; - return b; - } + b = dtoa_balloc(1 MTa); + b->x[0] = i; + b->wds = 1; + return b; +} - static Bigint * -mult(Bigint *a, Bigint *b MTd) -{ - Bigint *c; - int k, wa, wb, wc; - ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; - ULong y; +static Bigint *dtoa_mult(Bigint *a, Bigint *b MTd) { + Bigint *c; + int k, wa, wb, wc; + ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; + ULong y; #ifdef ULLong - ULLong carry, z; + ULLong carry, z; #else - ULong carry, z; + ULong carry, z; #ifdef Pack_32 - ULong z2; + ULong z2; #endif #endif - if (a->wds < b->wds) { - c = a; - a = b; - b = c; - } - k = a->k; - wa = a->wds; - wb = b->wds; - wc = wa + wb; - if (wc > a->maxwds) - k++; - c = Balloc(k MTa); - for(x = c->x, xa = x + wc; x < xa; x++) - *x = 0; - xa = a->x; - xae = xa + wa; - xb = b->x; - xbe = xb + wb; - xc0 = c->x; + if (a->wds < b->wds) { + c = a; + a = b; + b = c; + } + k = a->k; + wa = a->wds; + wb = b->wds; + wc = wa + wb; + if (wc > a->maxwds) k++; + c = dtoa_balloc(k MTa); + for (x = c->x, xa = x + wc; x < xa; x++) *x = 0; + xa = a->x; + xae = xa + wa; + xb = b->x; + xbe = xb + wb; + xc0 = c->x; #ifdef ULLong - for(; xb < xbe; xc0++) { - if ((y = *xb++)) { - x = xa; - xc = xc0; - carry = 0; - do { - z = *x++ * (ULLong)y + *xc + carry; - carry = z >> 32; - *xc++ = z & FFFFFFFF; - } - while(x < xae); - *xc = carry; - } - } + for (; xb < xbe; xc0++) { + if ((y = *xb++)) { + x = xa; + xc = xc0; + carry = 0; + do { + z = *x++ * (ULLong)y + *xc + carry; + carry = z >> 32; + *xc++ = z & FFFFFFFF; + } while (x < xae); + *xc = carry; + } + } #else #ifdef Pack_32 - for(; xb < xbe; xb++, xc0++) { - if (y = *xb & 0xffff) { - x = xa; - xc = xc0; - carry = 0; - do { - z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; - carry = z >> 16; - z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; - carry = z2 >> 16; - Storeinc(xc, z2, z); - } - while(x < xae); - *xc = carry; - } - if (y = *xb >> 16) { - x = xa; - xc = xc0; - carry = 0; - z2 = *xc; - do { - z = (*x & 0xffff) * y + (*xc >> 16) + carry; - carry = z >> 16; - Storeinc(xc, z, z2); - z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; - carry = z2 >> 16; - } - while(x < xae); - *xc = z2; - } - } + for (; xb < xbe; xb++, xc0++) { + if (y = *xb & 0xffff) { + x = xa; + xc = xc0; + carry = 0; + do { + z = (*x & 0xffff) * y + (*xc & 0xffff) + carry; + carry = z >> 16; + z2 = (*x++ >> 16) * y + (*xc >> 16) + carry; + carry = z2 >> 16; + Storeinc(xc, z2, z); + } while (x < xae); + *xc = carry; + } + if (y = *xb >> 16) { + x = xa; + xc = xc0; + carry = 0; + z2 = *xc; + do { + z = (*x & 0xffff) * y + (*xc >> 16) + carry; + carry = z >> 16; + Storeinc(xc, z, z2); + z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry; + carry = z2 >> 16; + } while (x < xae); + *xc = z2; + } + } #else - for(; xb < xbe; xc0++) { - if (y = *xb++) { - x = xa; - xc = xc0; - carry = 0; - do { - z = *x++ * y + *xc + carry; - carry = z >> 16; - *xc++ = z & 0xffff; - } - while(x < xae); - *xc = carry; - } - } + for (; xb < xbe; xc0++) { + if (y = *xb++) { + x = xa; + xc = xc0; + carry = 0; + do { + z = *x++ * y + *xc + carry; + carry = z >> 16; + *xc++ = z & 0xffff; + } while (x < xae); + *xc = carry; + } + } #endif #endif - for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ; - c->wds = wc; - return c; - } + for (xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) + ; + c->wds = wc; + return c; +} - static Bigint * -pow5mult(Bigint *b, int k MTd) -{ - Bigint *b1, *p5, *p51; +static Bigint *dtoa_pow5mult(Bigint *b, int k MTd) { + Bigint *b1, *p5, *p51; #ifdef MULTIPLE_THREADS - ThInfo *TI; + ThInfo *TI; #endif - int i; - static int p05[3] = { 5, 25, 125 }; + int i; + static int p05[3] = {5, 25, 125}; - if ((i = k & 3)) - b = multadd(b, p05[i-1], 0 MTa); + if ((i = k & 3)) b = dtoa_multadd(b, p05[i - 1], 0 MTa); - if (!(k >>= 2)) - return b; -#ifdef MULTIPLE_THREADS - if (!(TI = *PTI)) - *PTI = TI = get_TI(); -#endif - if (!(p5 = p5s)) { - /* first time */ + if (!(k >>= 2)) return b; #ifdef MULTIPLE_THREADS - if (!(TI = *PTI)) - *PTI = TI = get_TI(); - if (TI == &TI0) - ACQUIRE_DTOA_LOCK(1); - if (!(p5 = p5s)) { - p5 = p5s = i2b(625 MTa); - p5->next = 0; - } - if (TI == &TI0) - FREE_DTOA_LOCK(1); + if (!(TI = *PTI)) *PTI = TI = get_TI(); +#endif + if (!(p5 = p5s)) { + /* first time */ +#ifdef MULTIPLE_THREADS + if (!(TI = *PTI)) *PTI = TI = get_TI(); + if (TI == &TI0) ACQUIRE_DTOA_LOCK(1); + if (!(p5 = p5s)) { + p5 = p5s = dtoa_i2b(625 MTa); + p5->next = 0; + } + if (TI == &TI0) FREE_DTOA_LOCK(1); #else - p5 = p5s = i2b(625 MTa); - p5->next = 0; + p5 = p5s = dtoa_i2b(625 MTa); + p5->next = 0; #endif - } - for(;;) { - if (k & 1) { - b1 = mult(b, p5 MTa); - Bfree(b MTa); - b = b1; - } - if (!(k >>= 1)) - break; - if (!(p51 = p5->next)) { + } + for (;;) { + if (k & 1) { + b1 = dtoa_mult(b, p5 MTa); + dtoa_bfree(b MTa); + b = b1; + } + if (!(k >>= 1)) break; + if (!(p51 = p5->next)) { #ifdef MULTIPLE_THREADS - if (!TI && !(TI = *PTI)) - *PTI = TI = get_TI(); - if (TI == &TI0) - ACQUIRE_DTOA_LOCK(1); - if (!(p51 = p5->next)) { - p51 = p5->next = mult(p5,p5 MTa); - p51->next = 0; - } - if (TI == &TI0) - FREE_DTOA_LOCK(1); + if (!TI && !(TI = *PTI)) *PTI = TI = get_TI(); + if (TI == &TI0) ACQUIRE_DTOA_LOCK(1); + if (!(p51 = p5->next)) { + p51 = p5->next = dtoa_mult(p5, p5 MTa); + p51->next = 0; + } + if (TI == &TI0) FREE_DTOA_LOCK(1); #else - p51 = p5->next = mult(p5,p5); - p51->next = 0; + p51 = p5->next = dtoa_mult(p5, p5); + p51->next = 0; #endif - } - p5 = p51; - } - return b; - } + } + p5 = p51; + } + return b; +} - static Bigint * -lshift(Bigint *b, int k MTd) -{ - int i, k1, n, n1; - Bigint *b1; - ULong *x, *x1, *xe, z; +static Bigint *dtoa_lshift(Bigint *b, int k MTd) { + int i, k1, n, n1; + Bigint *b1; + ULong *x, *x1, *xe, z; #ifdef Pack_32 - n = k >> 5; + n = k >> 5; #else - n = k >> 4; + n = k >> 4; #endif - k1 = b->k; - n1 = n + b->wds + 1; - for(i = b->maxwds; n1 > i; i <<= 1) - k1++; - b1 = Balloc(k1 MTa); - x1 = b1->x; - for(i = 0; i < n; i++) - *x1++ = 0; - x = b->x; - xe = x + b->wds; + k1 = b->k; + n1 = n + b->wds + 1; + for (i = b->maxwds; n1 > i; i <<= 1) k1++; + b1 = dtoa_balloc(k1 MTa); + x1 = b1->x; + for (i = 0; i < n; i++) *x1++ = 0; + x = b->x; + xe = x + b->wds; #ifdef Pack_32 - if (k &= 0x1f) { - k1 = 32 - k; - z = 0; - do { - *x1++ = *x << k | z; - z = *x++ >> k1; - } - while(x < xe); - if ((*x1 = z)) - ++n1; - } + if (k &= 0x1f) { + k1 = 32 - k; + z = 0; + do { + *x1++ = *x << k | z; + z = *x++ >> k1; + } while (x < xe); + if ((*x1 = z)) ++n1; + } #else - if (k &= 0xf) { - k1 = 16 - k; - z = 0; - do { - *x1++ = *x << k & 0xffff | z; - z = *x++ >> k1; - } - while(x < xe); - if (*x1 = z) - ++n1; - } + if (k &= 0xf) { + k1 = 16 - k; + z = 0; + do { + *x1++ = *x << k & 0xffff | z; + z = *x++ >> k1; + } while (x < xe); + if (*x1 = z) ++n1; + } #endif - else do - *x1++ = *x++; - while(x < xe); - b1->wds = n1 - 1; - Bfree(b MTa); - return b1; - } + else + do + *x1++ = *x++; + while (x < xe); + b1->wds = n1 - 1; + dtoa_bfree(b MTa); + return b1; +} - static int -cmp(Bigint *a, Bigint *b) -{ - ULong *xa, *xa0, *xb, *xb0; - int i, j; +static int dtoa_cmp(Bigint *a, Bigint *b) { + ULong *xa, *xa0, *xb, *xb0; + int i, j; - i = a->wds; - j = b->wds; + i = a->wds; + j = b->wds; #ifdef DEBUG - if (i > 1 && !a->x[i-1]) - Bug("cmp called with a->x[a->wds-1] == 0"); - if (j > 1 && !b->x[j-1]) - Bug("cmp called with b->x[b->wds-1] == 0"); + if (i > 1 && !a->x[i - 1]) Bug("dtoa_cmp called with a->x[a->wds-1] == 0"); + if (j > 1 && !b->x[j - 1]) Bug("dtoa_cmp called with b->x[b->wds-1] == 0"); #endif - if (i -= j) - return i; - xa0 = a->x; - xa = xa0 + j; - xb0 = b->x; - xb = xb0 + j; - for(;;) { - if (*--xa != *--xb) - return *xa < *xb ? -1 : 1; - if (xa <= xa0) - break; - } - return 0; - } + if (i -= j) return i; + xa0 = a->x; + xa = xa0 + j; + xb0 = b->x; + xb = xb0 + j; + for (;;) { + if (*--xa != *--xb) return *xa < *xb ? -1 : 1; + if (xa <= xa0) break; + } + return 0; +} - static Bigint * -diff(Bigint *a, Bigint *b MTd) -{ - Bigint *c; - int i, wa, wb; - ULong *xa, *xae, *xb, *xbe, *xc; +static Bigint *dtoa_diff(Bigint *a, Bigint *b MTd) { + Bigint *c; + int i, wa, wb; + ULong *xa, *xae, *xb, *xbe, *xc; #ifdef ULLong - ULLong borrow, y; + ULLong borrow, y; #else - ULong borrow, y; + ULong borrow, y; #ifdef Pack_32 - ULong z; + ULong z; #endif #endif - i = cmp(a,b); - if (!i) { - c = Balloc(0 MTa); - c->wds = 1; - c->x[0] = 0; - return c; - } - if (i < 0) { - c = a; - a = b; - b = c; - i = 1; - } - else - i = 0; - c = Balloc(a->k MTa); - c->sign = i; - wa = a->wds; - xa = a->x; - xae = xa + wa; - wb = b->wds; - xb = b->x; - xbe = xb + wb; - xc = c->x; - borrow = 0; + i = dtoa_cmp(a, b); + if (!i) { + c = dtoa_balloc(0 MTa); + c->wds = 1; + c->x[0] = 0; + return c; + } + if (i < 0) { + c = a; + a = b; + b = c; + i = 1; + } else + i = 0; + c = dtoa_balloc(a->k MTa); + c->sign = i; + wa = a->wds; + xa = a->x; + xae = xa + wa; + wb = b->wds; + xb = b->x; + xbe = xb + wb; + xc = c->x; + borrow = 0; #ifdef ULLong - do { - y = (ULLong)*xa++ - *xb++ - borrow; - borrow = y >> 32 & (ULong)1; - *xc++ = y & FFFFFFFF; - } - while(xb < xbe); - while(xa < xae) { - y = *xa++ - borrow; - borrow = y >> 32 & (ULong)1; - *xc++ = y & FFFFFFFF; - } + do { + y = (ULLong)*xa++ - *xb++ - borrow; + borrow = y >> 32 & (ULong)1; + *xc++ = y & FFFFFFFF; + } while (xb < xbe); + while (xa < xae) { + y = *xa++ - borrow; + borrow = y >> 32 & (ULong)1; + *xc++ = y & FFFFFFFF; + } #else #ifdef Pack_32 - do { - y = (*xa & 0xffff) - (*xb & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*xa++ >> 16) - (*xb++ >> 16) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(xc, z, y); - } - while(xb < xbe); - while(xa < xae) { - y = (*xa & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*xa++ >> 16) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(xc, z, y); - } + do { + y = (*xa & 0xffff) - (*xb & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*xa++ >> 16) - (*xb++ >> 16) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } while (xb < xbe); + while (xa < xae) { + y = (*xa & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*xa++ >> 16) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(xc, z, y); + } #else - do { - y = *xa++ - *xb++ - borrow; - borrow = (y & 0x10000) >> 16; - *xc++ = y & 0xffff; - } - while(xb < xbe); - while(xa < xae) { - y = *xa++ - borrow; - borrow = (y & 0x10000) >> 16; - *xc++ = y & 0xffff; - } + do { + y = *xa++ - *xb++ - borrow; + borrow = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } while (xb < xbe); + while (xa < xae) { + y = *xa++ - borrow; + borrow = (y & 0x10000) >> 16; + *xc++ = y & 0xffff; + } #endif #endif - while(!*--xc) - wa--; - c->wds = wa; - return c; - } + while (!*--xc) wa--; + c->wds = wa; + return c; +} - static double -ulp(U *x) -{ - Long L; - U u; +static double ulp(U *x) { + Long L; + U u; - L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; + L = (word0(x) & Exp_mask) - (P - 1) * Exp_msk1; #ifndef Avoid_Underflow #ifndef Sudden_Underflow - if (L > 0) { + if (L > 0) { #endif #endif #ifdef IBM - L |= Exp_msk1 >> 4; + L |= Exp_msk1 >> 4; #endif - word0(&u) = L; - word1(&u) = 0; + word0(&u) = L; + word1(&u) = 0; #ifndef Avoid_Underflow #ifndef Sudden_Underflow - } - else { - L = -L >> Exp_shift; - if (L < Exp_shift) { - word0(&u) = 0x80000 >> L; - word1(&u) = 0; - } - else { - word0(&u) = 0; - L -= Exp_shift; - word1(&u) = L >= 31 ? 1 : 1 << 31 - L; - } - } + } else { + L = -L >> Exp_shift; + if (L < Exp_shift) { + word0(&u) = 0x80000 >> L; + word1(&u) = 0; + } else { + word0(&u) = 0; + L -= Exp_shift; + word1(&u) = L >= 31 ? 1 : 1 << 31 - L; + } + } #endif #endif - return dval(&u); - } + return dval(&u); +} - static double -b2d(Bigint *a, int *e) -{ - ULong *xa, *xa0, w, y, z; - int k; - U d; +static double dtoa_b2d(Bigint *a, int *e) { + ULong *xa, *xa0, w, y, z; + int k; + U d; #ifdef VAX - ULong d0, d1; + ULong d0, d1; #else #define d0 word0(&d) #define d1 word1(&d) #endif - xa0 = a->x; - xa = xa0 + a->wds; - y = *--xa; + xa0 = a->x; + xa = xa0 + a->wds; + y = *--xa; #ifdef DEBUG - if (!y) Bug("zero y in b2d"); + if (!y) Bug("zero y in dtoa_b2d"); #endif - k = hi0bits(y); - *e = 32 - k; + k = dtoa_hi0bits(y); + *e = 32 - k; #ifdef Pack_32 - if (k < Ebits) { - d0 = Exp_1 | y >> (Ebits - k); - w = xa > xa0 ? *--xa : 0; - d1 = y << ((32-Ebits) + k) | w >> (Ebits - k); - goto ret_d; - } - z = xa > xa0 ? *--xa : 0; - if (k -= Ebits) { - d0 = Exp_1 | y << k | z >> (32 - k); - y = xa > xa0 ? *--xa : 0; - d1 = z << k | y >> (32 - k); - } - else { - d0 = Exp_1 | y; - d1 = z; - } + if (k < Ebits) { + d0 = Exp_1 | y >> (Ebits - k); + w = xa > xa0 ? *--xa : 0; + d1 = y << ((32 - Ebits) + k) | w >> (Ebits - k); + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + if (k -= Ebits) { + d0 = Exp_1 | y << k | z >> (32 - k); + y = xa > xa0 ? *--xa : 0; + d1 = z << k | y >> (32 - k); + } else { + d0 = Exp_1 | y; + d1 = z; + } #else - if (k < Ebits + 16) { - z = xa > xa0 ? *--xa : 0; - d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; - w = xa > xa0 ? *--xa : 0; - y = xa > xa0 ? *--xa : 0; - d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; - goto ret_d; - } - z = xa > xa0 ? *--xa : 0; - w = xa > xa0 ? *--xa : 0; - k -= Ebits + 16; - d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; - y = xa > xa0 ? *--xa : 0; - d1 = w << k + 16 | y << k; + if (k < Ebits + 16) { + z = xa > xa0 ? *--xa : 0; + d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k; + w = xa > xa0 ? *--xa : 0; + y = xa > xa0 ? *--xa : 0; + d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k; + goto ret_d; + } + z = xa > xa0 ? *--xa : 0; + w = xa > xa0 ? *--xa : 0; + k -= Ebits + 16; + d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k; + y = xa > xa0 ? *--xa : 0; + d1 = w << k + 16 | y << k; #endif - ret_d: +ret_d: #ifdef VAX - word0(&d) = d0 >> 16 | d0 << 16; - word1(&d) = d1 >> 16 | d1 << 16; + word0(&d) = d0 >> 16 | d0 << 16; + word1(&d) = d1 >> 16 | d1 << 16; #else #undef d0 #undef d1 #endif - return dval(&d); - } + return dval(&d); +} - static Bigint * -d2b(U *d, int *e, int *bits MTd) -{ - Bigint *b; - int de, k; - ULong *x, y, z; +static Bigint *dtoa_d2b(U *d, int *e, int *bits MTd) { + Bigint *b; + int de, k; + ULong *x, y, z; #ifndef Sudden_Underflow - int i; + int i; #endif #ifdef VAX - ULong d0, d1; - d0 = word0(d) >> 16 | word0(d) << 16; - d1 = word1(d) >> 16 | word1(d) << 16; + ULong d0, d1; + d0 = word0(d) >> 16 | word0(d) << 16; + d1 = word1(d) >> 16 | word1(d) << 16; #else #define d0 word0(d) #define d1 word1(d) #endif #ifdef Pack_32 - b = Balloc(1 MTa); + b = dtoa_balloc(1 MTa); #else - b = Balloc(2 MTa); + b = dtoa_balloc(2 MTa); #endif - x = b->x; + x = b->x; - z = d0 & Frac_mask; - d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ + z = d0 & Frac_mask; + d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ #ifdef Sudden_Underflow - de = (int)(d0 >> Exp_shift); + de = (int)(d0 >> Exp_shift); #ifndef IBM - z |= Exp_msk11; + z |= Exp_msk11; #endif #else - if ((de = (int)(d0 >> Exp_shift))) - z |= Exp_msk1; + if ((de = (int)(d0 >> Exp_shift))) z |= Exp_msk1; #endif #ifdef Pack_32 - if ((y = d1)) { - if ((k = lo0bits(&y))) { - x[0] = y | z << (32 - k); - z >>= k; - } - else - x[0] = y; + if ((y = d1)) { + if ((k = dtoa_lo0bits(&y))) { + x[0] = y | z << (32 - k); + z >>= k; + } else + x[0] = y; #ifndef Sudden_Underflow - i = + i = #endif - b->wds = (x[1] = z) ? 2 : 1; - } - else { - k = lo0bits(&z); - x[0] = z; + b->wds = (x[1] = z) ? 2 : 1; + } else { + k = dtoa_lo0bits(&z); + x[0] = z; #ifndef Sudden_Underflow - i = + i = #endif - b->wds = 1; - k += 32; - } + b->wds = 1; + k += 32; + } #else - if (y = d1) { - if (k = lo0bits(&y)) - if (k >= 16) { - x[0] = y | z << 32 - k & 0xffff; - x[1] = z >> k - 16 & 0xffff; - x[2] = z >> k; - i = 2; - } - else { - x[0] = y & 0xffff; - x[1] = y >> 16 | z << 16 - k & 0xffff; - x[2] = z >> k & 0xffff; - x[3] = z >> k+16; - i = 3; - } - else { - x[0] = y & 0xffff; - x[1] = y >> 16; - x[2] = z & 0xffff; - x[3] = z >> 16; - i = 3; - } - } - else { + if (y = d1) { + if (k = dtoa_lo0bits(&y)) + if (k >= 16) { + x[0] = y | z << 32 - k & 0xffff; + x[1] = z >> k - 16 & 0xffff; + x[2] = z >> k; + i = 2; + } else { + x[0] = y & 0xffff; + x[1] = y >> 16 | z << 16 - k & 0xffff; + x[2] = z >> k & 0xffff; + x[3] = z >> k + 16; + i = 3; + } + else { + x[0] = y & 0xffff; + x[1] = y >> 16; + x[2] = z & 0xffff; + x[3] = z >> 16; + i = 3; + } + } else { #ifdef DEBUG - if (!z) - Bug("Zero passed to d2b"); + if (!z) Bug("Zero passed to dtoa_d2b"); #endif - k = lo0bits(&z); - if (k >= 16) { - x[0] = z; - i = 0; - } - else { - x[0] = z & 0xffff; - x[1] = z >> 16; - i = 1; - } - k += 32; - } - while(!x[i]) - --i; - b->wds = i + 1; + k = dtoa_lo0bits(&z); + if (k >= 16) { + x[0] = z; + i = 0; + } else { + x[0] = z & 0xffff; + x[1] = z >> 16; + i = 1; + } + k += 32; + } + while (!x[i]) --i; + b->wds = i + 1; #endif #ifndef Sudden_Underflow - if (de) { + if (de) { #endif #ifdef IBM - *e = (de - Bias - (P-1) << 2) + k; - *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask); + *e = (de - Bias - (P - 1) << 2) + k; + *bits = 4 * P + 8 - k - dtoa_hi0bits(word0(d) & Frac_mask); #else - *e = de - Bias - (P-1) + k; - *bits = P - k; + *e = de - Bias - (P - 1) + k; + *bits = P - k; #endif #ifndef Sudden_Underflow - } - else { - *e = de - Bias - (P-1) + 1 + k; + } else { + *e = de - Bias - (P - 1) + 1 + k; #ifdef Pack_32 - *bits = 32*i - hi0bits(x[i-1]); + *bits = 32 * i - dtoa_hi0bits(x[i - 1]); #else - *bits = (i+2)*16 - hi0bits(x[i]); + *bits = (i + 2) * 16 - dtoa_hi0bits(x[i]); #endif - } + } #endif - return b; - } + return b; +} #undef d0 #undef d1 - static double -ratio(Bigint *a, Bigint *b) -{ - U da, db; - int k, ka, kb; +static double dtoaratio(Bigint *a, Bigint *b) { + U da, db; + int k, ka, kb; - dval(&da) = b2d(a, &ka); - dval(&db) = b2d(b, &kb); + dval(&da) = dtoa_b2d(a, &ka); + dval(&db) = dtoa_b2d(b, &kb); #ifdef Pack_32 - k = ka - kb + 32*(a->wds - b->wds); + k = ka - kb + 32 * (a->wds - b->wds); #else - k = ka - kb + 16*(a->wds - b->wds); + k = ka - kb + 16 * (a->wds - b->wds); #endif #ifdef IBM - if (k > 0) { - word0(&da) += (k >> 2)*Exp_msk1; - if (k &= 3) - dval(&da) *= 1u << k; - } - else { - k = -k; - word0(&db) += (k >> 2)*Exp_msk1; - if (k &= 3) - dval(&db) *= 1u << k; - } + if (k > 0) { + word0(&da) += (k >> 2) * Exp_msk1; + if (k &= 3) dval(&da) *= 1u << k; + } else { + k = -k; + word0(&db) += (k >> 2) * Exp_msk1; + if (k &= 3) dval(&db) *= 1u << k; + } #else - if (k > 0) - word0(&da) += k*Exp_msk1; - else { - k = -k; - word0(&db) += k*Exp_msk1; - } + if (k > 0) + word0(&da) += k * Exp_msk1; + else { + k = -k; + word0(&db) += k * Exp_msk1; + } #endif - return dval(&da) / dval(&db); - } + return dval(&da) / dval(&db); +} - static const double -tens[] = { - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, - 1e20, 1e21, 1e22 +static const double kDtoaTens[] = {1e0, + 1e1, + 1e2, + 1e3, + 1e4, + 1e5, + 1e6, + 1e7, + 1e8, + 1e9, + 1e10, + 1e11, + 1e12, + 1e13, + 1e14, + 1e15, + 1e16, + 1e17, + 1e18, + 1e19, + 1e20, + 1e21, + 1e22 #ifdef VAX - , 1e23, 1e24 + , + 1e23, + 1e24 #endif - }; +}; - static const double +static const double #ifdef IEEE_Arith -bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 }; -static const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, + kDtoaBigTens[] = {1e16, 1e32, 1e64, 1e128, 1e256}; +static const double kDtoaTinyTens[] = { + 1e-16, 1e-32, 1e-64, 1e-128, #ifdef Avoid_Underflow - 9007199254740992.*9007199254740992.e-256 - /* = 2^106 * 1e-256 */ + 9007199254740992. * 9007199254740992.e-256 +/* = 2^106 * 1e-256 */ #else - 1e-256 + 1e-256 #endif - }; -/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */ +}; +/* The factor of 2^53 in kDtoaTinyTens[4] helps us avoid setting the underflow + */ /* flag unnecessarily. It leads to a song and dance at the end of strtod. */ #define Scale_Bit 0x10 #define n_bigtens 5 #else #ifdef IBM -bigtens[] = { 1e16, 1e32, 1e64 }; -static const double tinytens[] = { 1e-16, 1e-32, 1e-64 }; + kDtoaBigTens[] = {1e16, 1e32, 1e64}; +static const double kDtoaTinyTens[] = {1e-16, 1e-32, 1e-64}; #define n_bigtens 3 #else -bigtens[] = { 1e16, 1e32 }; -static const double tinytens[] = { 1e-16, 1e-32 }; + kDtoaBigTens[] = {1e16, 1e32}; +static const double kDtoaTinyTens[] = {1e-16, 1e-32}; #define n_bigtens 2 #endif #endif @@ -2523,24 +2422,21 @@ hexdig_init(void) /* Use of hexdig_init omitted 20121220 to avoid a */ htinit(hexdig, USC "ABCDEF", 0x10 + 10); } #else -static unsigned char hexdig[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0, - 0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - }; +static unsigned char kDtoaHexdig[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 0, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 26, 27, 28, 29, 30, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif #endif /* } Need_Hexdig */ @@ -2554,2373 +2450,2181 @@ static unsigned char hexdig[256] = { #define NAN_WORD1 0 #endif - static int -match(const char **sp, const char *t) -{ - int c, d; - const char *s = *sp; +static int dtoa_match(const char **sp, const char *t) { + int c, d; + const char *s = *sp; - while((d = *t++)) { - if ((c = *++s) >= 'A' && c <= 'Z') - c += 'a' - 'A'; - if (c != d) - return 0; - } - *sp = s + 1; - return 1; - } + while ((d = *t++)) { + if ((c = *++s) >= 'A' && c <= 'Z') c += 'a' - 'A'; + if (c != d) return 0; + } + *sp = s + 1; + return 1; +} #ifndef No_Hex_NaN - static void -hexnan(U *rvp, const char **sp) -{ - ULong c, x[2]; - const char *s; - int c1, havedig, udx0, xshift; +static void dtoa_hexnan(U *rvp, const char **sp) { + ULong c, x[2]; + const char *s; + int c1, havedig, udx0, xshift; - /**** if (!hexdig['0']) hexdig_init(); ****/ - x[0] = x[1] = 0; - havedig = xshift = 0; - udx0 = 1; - s = *sp; - /* allow optional initial 0x or 0X */ - while((c = *(const unsigned char*)(s+1)) && c <= ' ') - ++s; - if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')) - s += 2; - while((c = *(const unsigned char*)++s)) { - if ((c1 = hexdig[c])) - c = c1 & 0xf; - else if (c <= ' ') { - if (udx0 && havedig) { - udx0 = 0; - xshift = 1; - } - continue; - } + /**** if (!hexdig['0']) hexdig_init(); ****/ + x[0] = x[1] = 0; + havedig = xshift = 0; + udx0 = 1; + s = *sp; + /* allow optional initial 0x or 0X */ + while ((c = *(const unsigned char *)(s + 1)) && c <= ' ') ++s; + if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')) s += 2; + while ((c = *(const unsigned char *)++s)) { + if ((c1 = kDtoaHexdig[c])) + c = c1 & 0xf; + else if (c <= ' ') { + if (udx0 && havedig) { + udx0 = 0; + xshift = 1; + } + continue; + } #ifdef GDTOA_NON_PEDANTIC_NANCHECK - else if (/*(*/ c == ')' && havedig) { - *sp = s + 1; - break; - } - else - return; /* invalid form: don't change *sp */ + else if (/*(*/ c == ')' && havedig) { + *sp = s + 1; + break; + } else + return; /* invalid form: don't change *sp */ #else - else { - do { - if (/*(*/ c == ')') { - *sp = s + 1; - break; - } - } while((c = *++s)); - break; - } + else { + do { + if (/*(*/ c == ')') { + *sp = s + 1; + break; + } + } while ((c = *++s)); + break; + } #endif - havedig = 1; - if (xshift) { - xshift = 0; - x[0] = x[1]; - x[1] = 0; - } - if (udx0) - x[0] = (x[0] << 4) | (x[1] >> 28); - x[1] = (x[1] << 4) | c; - } - if ((x[0] &= 0xfffff) || x[1]) { - word0(rvp) = Exp_mask | x[0]; - word1(rvp) = x[1]; - } - } + havedig = 1; + if (xshift) { + xshift = 0; + x[0] = x[1]; + x[1] = 0; + } + if (udx0) x[0] = (x[0] << 4) | (x[1] >> 28); + x[1] = (x[1] << 4) | c; + } + if ((x[0] &= 0xfffff) || x[1]) { + word0(rvp) = Exp_mask | x[0]; + word1(rvp) = x[1]; + } +} #endif /*No_Hex_NaN*/ #endif /* INFNAN_CHECK */ #ifdef Pack_32 #define ULbits 32 #define kshift 5 -#define kmask 31 +#define kmask 31 #else #define ULbits 16 #define kshift 4 -#define kmask 15 +#define kmask 15 #endif #if !defined(NO_HEX_FP) || defined(Honor_FLT_ROUNDS) /*{*/ - static Bigint * -increment(Bigint *b MTd) -{ - ULong *x, *xe; - Bigint *b1; +static Bigint *increment(Bigint *b MTd) { + ULong *x, *xe; + Bigint *b1; - x = b->x; - xe = x + b->wds; - do { - if (*x < (ULong)0xffffffffL) { - ++*x; - return b; - } - *x++ = 0; - } while(x < xe); - { - if (b->wds >= b->maxwds) { - b1 = Balloc(b->k+1 MTa); - Bcopy(b1,b); - Bfree(b MTa); - b = b1; - } - b->x[b->wds++] = 1; - } - return b; - } + x = b->x; + xe = x + b->wds; + do { + if (*x < (ULong)0xffffffffL) { + ++*x; + return b; + } + *x++ = 0; + } while (x < xe); + { + if (b->wds >= b->maxwds) { + b1 = dtoa_balloc(b->k + 1 MTa); + Bcopy(b1, b); + dtoa_bfree(b MTa); + b = b1; + } + b->x[b->wds++] = 1; + } + return b; +} #endif /*}*/ #ifndef NO_HEX_FP /*{*/ - static void -rshift(Bigint *b, int k) -{ - ULong *x, *x1, *xe, y; - int n; +static void dtoa_rshift(Bigint *b, int k) { + ULong *x, *x1, *xe, y; + int n; - x = x1 = b->x; - n = k >> kshift; - if (n < b->wds) { - xe = x + b->wds; - x += n; - if (k &= kmask) { - n = 32 - k; - y = *x++ >> k; - while(x < xe) { - *x1++ = (y | (*x << n)) & 0xffffffff; - y = *x++ >> k; - } - if ((*x1 = y) !=0) - x1++; - } - else - while(x < xe) - *x1++ = *x++; - } - if ((b->wds = x1 - b->x) == 0) - b->x[0] = 0; - } + x = x1 = b->x; + n = k >> kshift; + if (n < b->wds) { + xe = x + b->wds; + x += n; + if (k &= kmask) { + n = 32 - k; + y = *x++ >> k; + while (x < xe) { + *x1++ = (y | (*x << n)) & 0xffffffff; + y = *x++ >> k; + } + if ((*x1 = y) != 0) x1++; + } else + while (x < xe) *x1++ = *x++; + } + if ((b->wds = x1 - b->x) == 0) b->x[0] = 0; +} - static ULong -any_on(Bigint *b, int k) -{ - int n, nwds; - ULong *x, *x0, x1, x2; +static ULong dtoa_any_on(Bigint *b, int k) { + int n, nwds; + ULong *x, *x0, x1, x2; - x = b->x; - nwds = b->wds; - n = k >> kshift; - if (n > nwds) - n = nwds; - else if (n < nwds && (k &= kmask)) { - x1 = x2 = x[n]; - x1 >>= k; - x1 <<= k; - if (x1 != x2) - return 1; - } - x0 = x; - x += n; - while(x > x0) - if (*--x) - return 1; - return 0; - } + x = b->x; + nwds = b->wds; + n = k >> kshift; + if (n > nwds) + n = nwds; + else if (n < nwds && (k &= kmask)) { + x1 = x2 = x[n]; + x1 >>= k; + x1 <<= k; + if (x1 != x2) return 1; + } + x0 = x; + x += n; + while (x > x0) + if (*--x) return 1; + return 0; +} -enum { /* rounding values: same as FLT_ROUNDS */ - Round_zero = 0, - Round_near = 1, - Round_up = 2, - Round_down = 3 - }; +enum { /* rounding values: same as FLT_ROUNDS */ + Round_zero = 0, + Round_near = 1, + Round_up = 2, + Round_down = 3 +}; -static void -gethex( const char **sp, U *rvp, int rounding, int sign MTd) -{ - Bigint *b; - const unsigned char *decpt, *s0, *s, *s1; - Long e, e1; - ULong L, lostbits, *x; - int big, denorm, esign, havedig, k, n, nbits, up, zret; +static void gethex(const char **sp, U *rvp, int rounding, int sign MTd) { + Bigint *b; + const unsigned char *decpt, *s0, *s, *s1; + Long e, e1; + ULong L, lostbits, *x; + int big, denorm, esign, havedig, k, n, nbits, up, zret; #ifdef IBM - int j; + int j; #endif - enum { + enum { #ifdef IEEE_Arith /*{{*/ - emax = 0x7fe - Bias - P + 1, - emin = Emin - P + 1 + emax = 0x7fe - Bias - P + 1, + emin = Emin - P + 1 #else /*}{*/ - emin = Emin - P, + emin = Emin - P, #ifdef VAX - emax = 0x7ff - Bias - P + 1 + emax = 0x7ff - Bias - P + + 1 #endif #ifdef IBM - emax = 0x7f - Bias - P + emax = 0x7f - Bias - P #endif #endif /*}}*/ - }; + }; #ifdef USE_LOCALE - int i; + int i; #ifdef NO_LOCALE_CACHE - const unsigned char *decimalpoint = (unsigned char*) - localeconv()->decimal_point; + const unsigned char *decimalpoint = + (unsigned char *)localeconv()->decimal_point; #else - const unsigned char *decimalpoint; - static unsigned char *decimalpoint_cache; - if (!(s0 = decimalpoint_cache)) { - s0 = (unsigned char*)localeconv()->decimal_point; - if ((decimalpoint_cache = (unsigned char*) - MALLOC(strlen((const char*)s0) + 1))) { - strcpy((char*)decimalpoint_cache, (const char*)s0); - s0 = decimalpoint_cache; - } - } - decimalpoint = s0; + const unsigned char *decimalpoint; + static unsigned char *decimalpoint_cache; + if (!(s0 = decimalpoint_cache)) { + s0 = (unsigned char *)localeconv()->decimal_point; + if ((decimalpoint_cache = + (unsigned char *)MALLOC(strlen((const char *)s0) + 1))) { + strcpy((char *)decimalpoint_cache, (const char *)s0); + s0 = decimalpoint_cache; + } + } + decimalpoint = s0; #endif #endif - /**** if (!hexdig['0']) hexdig_init(); ****/ - havedig = 0; - s0 = *(const unsigned char **)sp + 2; - while(s0[havedig] == '0') - havedig++; - s0 += havedig; - s = s0; - decpt = 0; - zret = 0; - e = 0; - if (hexdig[*s]) - havedig++; - else { - zret = 1; + /**** if (!hexdig['0']) hexdig_init(); ****/ + havedig = 0; + s0 = *(const unsigned char **)sp + 2; + while (s0[havedig] == '0') havedig++; + s0 += havedig; + s = s0; + decpt = 0; + zret = 0; + e = 0; + if (kDtoaHexdig[*s]) + havedig++; + else { + zret = 1; #ifdef USE_LOCALE - for(i = 0; decimalpoint[i]; ++i) { - if (s[i] != decimalpoint[i]) - goto pcheck; - } - decpt = s += i; + for (i = 0; decimalpoint[i]; ++i) { + if (s[i] != decimalpoint[i]) goto pcheck; + } + decpt = s += i; #else - if (*s != '.') - goto pcheck; - decpt = ++s; + if (*s != '.') goto pcheck; + decpt = ++s; #endif - if (!hexdig[*s]) - goto pcheck; - while(*s == '0') - s++; - if (hexdig[*s]) - zret = 0; - havedig = 1; - s0 = s; - } - while(hexdig[*s]) - s++; + if (!kDtoaHexdig[*s]) goto pcheck; + while (*s == '0') s++; + if (kDtoaHexdig[*s]) zret = 0; + havedig = 1; + s0 = s; + } + while (kDtoaHexdig[*s]) s++; #ifdef USE_LOCALE - if (*s == *decimalpoint && !decpt) { - for(i = 1; decimalpoint[i]; ++i) { - if (s[i] != decimalpoint[i]) - goto pcheck; - } - decpt = s += i; + if (*s == *decimalpoint && !decpt) { + for (i = 1; decimalpoint[i]; ++i) { + if (s[i] != decimalpoint[i]) goto pcheck; + } + decpt = s += i; #else - if (*s == '.' && !decpt) { - decpt = ++s; + if (*s == '.' && !decpt) { + decpt = ++s; #endif - while(hexdig[*s]) - s++; - }/*}*/ - if (decpt) - e = -(((Long)(s-decpt)) << 2); - pcheck: - s1 = s; - big = esign = 0; - switch(*s) { - case 'p': - case 'P': - switch(*++s) { - case '-': - esign = 1; - /* no break */ - case '+': - s++; - } - if ((n = hexdig[*s]) == 0 || n > 0x19) { - s = s1; - break; - } - e1 = n - 0x10; - while((n = hexdig[*++s]) !=0 && n <= 0x19) { - if (e1 & 0xf8000000) - big = 1; - e1 = 10*e1 + n - 0x10; - } - if (esign) - e1 = -e1; - e += e1; - } - *sp = (char*)s; - if (!havedig) - *sp = (char*)s0 - 1; - if (zret) - goto retz1; - if (big) { - if (esign) { + while (kDtoaHexdig[*s]) s++; + } /*}*/ + if (decpt) e = -(((Long)(s - decpt)) << 2); +pcheck: + s1 = s; + big = esign = 0; + switch (*s) { + case 'p': + case 'P': + switch (*++s) { + case '-': + esign = 1; + /* no break */ + case '+': + s++; + } + if ((n = kDtoaHexdig[*s]) == 0 || n > 0x19) { + s = s1; + break; + } + e1 = n - 0x10; + while ((n = kDtoaHexdig[*++s]) != 0 && n <= 0x19) { + if (e1 & 0xf8000000) big = 1; + e1 = 10 * e1 + n - 0x10; + } + if (esign) e1 = -e1; + e += e1; + } + *sp = (char *)s; + if (!havedig) *sp = (char *)s0 - 1; + if (zret) goto retz1; + if (big) { + if (esign) { #ifdef IEEE_Arith - switch(rounding) { - case Round_up: - if (sign) - break; - goto ret_tiny; - case Round_down: - if (!sign) - break; - goto ret_tiny; - } + switch (rounding) { + case Round_up: + if (sign) break; + goto ret_tiny; + case Round_down: + if (!sign) break; + goto ret_tiny; + } #endif - goto retz; + goto retz; #ifdef IEEE_Arith - ret_tinyf: - Bfree(b MTa); - ret_tiny: - Set_errno(erange); - word0(rvp) = 0; - word1(rvp) = 1; - return; + ret_tinyf: + dtoa_bfree(b MTa); + ret_tiny: + Set_errno(erange); + word0(rvp) = 0; + word1(rvp) = 1; + return; #endif /* IEEE_Arith */ - } - switch(rounding) { - case Round_near: - goto ovfl1; - case Round_up: - if (!sign) - goto ovfl1; - goto ret_big; - case Round_down: - if (sign) - goto ovfl1; - goto ret_big; - } - ret_big: - word0(rvp) = Big0; - word1(rvp) = Big1; - return; - } - n = s1 - s0 - 1; - for(k = 0; n > (1 << (kshift-2)) - 1; n >>= 1) - k++; - b = Balloc(k MTa); - x = b->x; - n = 0; - L = 0; + } + switch (rounding) { + case Round_near: + goto ovfl1; + case Round_up: + if (!sign) goto ovfl1; + goto ret_big; + case Round_down: + if (sign) goto ovfl1; + goto ret_big; + } + ret_big: + word0(rvp) = Big0; + word1(rvp) = Big1; + return; + } + n = s1 - s0 - 1; + for (k = 0; n > (1 << (kshift - 2)) - 1; n >>= 1) k++; + b = dtoa_balloc(k MTa); + x = b->x; + n = 0; + L = 0; #ifdef USE_LOCALE - for(i = 0; decimalpoint[i+1]; ++i); + for (i = 0; decimalpoint[i + 1]; ++i) + ; #endif - while(s1 > s0) { + while (s1 > s0) { #ifdef USE_LOCALE - if (*--s1 == decimalpoint[i]) { - s1 -= i; - continue; - } + if (*--s1 == decimalpoint[i]) { + s1 -= i; + continue; + } #else - if (*--s1 == '.') - continue; + if (*--s1 == '.') continue; #endif - if (n == ULbits) { - *x++ = L; - L = 0; - n = 0; - } - L |= (hexdig[*s1] & 0x0f) << n; - n += 4; - } - *x++ = L; - b->wds = n = x - b->x; - n = ULbits*n - hi0bits(L); - nbits = Nbits; - lostbits = 0; - x = b->x; - if (n > nbits) { - n -= nbits; - if (any_on(b,n)) { - lostbits = 1; - k = n - 1; - if (x[k>>kshift] & 1 << (k & kmask)) { - lostbits = 2; - if (k > 0 && any_on(b,k)) - lostbits = 3; - } - } - rshift(b, n); - e += n; - } - else if (n < nbits) { - n = nbits - n; - b = lshift(b, n MTa); - e -= n; - x = b->x; - } - if (e > emax) { - ovfl: - Bfree(b MTa); - ovfl1: - Set_errno(erange); + if (n == ULbits) { + *x++ = L; + L = 0; + n = 0; + } + L |= (kDtoaHexdig[*s1] & 0x0f) << n; + n += 4; + } + *x++ = L; + b->wds = n = x - b->x; + n = ULbits * n - dtoa_hi0bits(L); + nbits = Nbits; + lostbits = 0; + x = b->x; + if (n > nbits) { + n -= nbits; + if (dtoa_any_on(b, n)) { + lostbits = 1; + k = n - 1; + if (x[k >> kshift] & 1 << (k & kmask)) { + lostbits = 2; + if (k > 0 && dtoa_any_on(b, k)) lostbits = 3; + } + } + dtoa_rshift(b, n); + e += n; + } else if (n < nbits) { + n = nbits - n; + b = dtoa_lshift(b, n MTa); + e -= n; + x = b->x; + } + if (e > emax) { + ovfl: + dtoa_bfree(b MTa); + ovfl1: + Set_errno(erange); #ifdef Honor_FLT_ROUNDS - switch (rounding) { - case Round_zero: - goto ret_big; - case Round_down: - if (!sign) - goto ret_big; - break; - case Round_up: - if (sign) - goto ret_big; - } + switch (rounding) { + case Round_zero: + goto ret_big; + case Round_down: + if (!sign) goto ret_big; + break; + case Round_up: + if (sign) goto ret_big; + } #endif - word0(rvp) = Exp_mask; - word1(rvp) = 0; - return; - } - denorm = 0; - if (e < emin) { - denorm = 1; - n = emin - e; - if (n >= nbits) { + word0(rvp) = Exp_mask; + word1(rvp) = 0; + return; + } + denorm = 0; + if (e < emin) { + denorm = 1; + n = emin - e; + if (n >= nbits) { #ifdef IEEE_Arith /*{*/ - switch (rounding) { - case Round_near: - if (n == nbits && (n < 2 || lostbits || any_on(b,n-1))) - goto ret_tinyf; - break; - case Round_up: - if (!sign) - goto ret_tinyf; - break; - case Round_down: - if (sign) - goto ret_tinyf; - } + switch (rounding) { + case Round_near: + if (n == nbits && (n < 2 || lostbits || dtoa_any_on(b, n - 1))) + goto ret_tinyf; + break; + case Round_up: + if (!sign) goto ret_tinyf; + break; + case Round_down: + if (sign) goto ret_tinyf; + } #endif /* } IEEE_Arith */ - Bfree(b MTa); - retz: - Set_errno(erange); - retz1: - rvp->d = 0.; - return; - } - k = n - 1; - if (lostbits) - lostbits = 1; - else if (k > 0) - lostbits = any_on(b,k); - if (x[k>>kshift] & 1 << (k & kmask)) - lostbits |= 2; - nbits -= n; - rshift(b,n); - e = emin; - } - if (lostbits) { - up = 0; - switch(rounding) { - case Round_zero: - break; - case Round_near: - if (lostbits & 2 - && (lostbits & 1) | (x[0] & 1)) - up = 1; - break; - case Round_up: - up = 1 - sign; - break; - case Round_down: - up = sign; - } - if (up) { - k = b->wds; - b = increment(b MTa); - x = b->x; - if (denorm) { + dtoa_bfree(b MTa); + retz: + Set_errno(erange); + retz1: + rvp->d = 0.; + return; + } + k = n - 1; + if (lostbits) + lostbits = 1; + else if (k > 0) + lostbits = dtoa_any_on(b, k); + if (x[k >> kshift] & 1 << (k & kmask)) lostbits |= 2; + nbits -= n; + dtoa_rshift(b, n); + e = emin; + } + if (lostbits) { + up = 0; + switch (rounding) { + case Round_zero: + break; + case Round_near: + if (lostbits & 2 && (lostbits & 1) | (x[0] & 1)) up = 1; + break; + case Round_up: + up = 1 - sign; + break; + case Round_down: + up = sign; + } + if (up) { + k = b->wds; + b = increment(b MTa); + x = b->x; + if (denorm) { #if 0 if (nbits == Nbits - 1 && x[nbits >> kshift] & 1 << (nbits & kmask)) denorm = 0; /* not currently used */ #endif - } - else if (b->wds > k - || ((n = nbits & kmask) !=0 - && hi0bits(x[k-1]) < 32-n)) { - rshift(b,1); - if (++e > Emax) - goto ovfl; - } - } - } + } else if (b->wds > k || ((n = nbits & kmask) != 0 && + dtoa_hi0bits(x[k - 1]) < 32 - n)) { + dtoa_rshift(b, 1); + if (++e > Emax) goto ovfl; + } + } + } #ifdef IEEE_Arith - if (denorm) - word0(rvp) = b->wds > 1 ? b->x[1] & ~0x100000 : 0; - else - word0(rvp) = (b->x[1] & ~0x100000) | ((e + 0x3ff + 52) << 20); - word1(rvp) = b->x[0]; + if (denorm) + word0(rvp) = b->wds > 1 ? b->x[1] & ~0x100000 : 0; + else + word0(rvp) = (b->x[1] & ~0x100000) | ((e + 0x3ff + 52) << 20); + word1(rvp) = b->x[0]; #endif #ifdef IBM - if ((j = e & 3)) { - k = b->x[0] & ((1u << j) - 1); - rshift(b,j); - if (k) { - switch(rounding) { - case Round_up: - if (!sign) - increment(b); - break; - case Round_down: - if (sign) - increment(b); - break; - case Round_near: - j = 1 << (j-1); - if (k & j && ((k & (j-1)) | lostbits)) - increment(b); - } - } - } - e >>= 2; - word0(rvp) = b->x[1] | ((e + 65 + 13) << 24); - word1(rvp) = b->x[0]; + if ((j = e & 3)) { + k = b->x[0] & ((1u << j) - 1); + dtoa_rshift(b, j); + if (k) { + switch (rounding) { + case Round_up: + if (!sign) increment(b); + break; + case Round_down: + if (sign) increment(b); + break; + case Round_near: + j = 1 << (j - 1); + if (k & j && ((k & (j - 1)) | lostbits)) increment(b); + } + } + } + e >>= 2; + word0(rvp) = b->x[1] | ((e + 65 + 13) << 24); + word1(rvp) = b->x[0]; #endif #ifdef VAX - /* The next two lines ignore swap of low- and high-order 2 bytes. */ - /* word0(rvp) = (b->x[1] & ~0x800000) | ((e + 129 + 55) << 23); */ - /* word1(rvp) = b->x[0]; */ - word0(rvp) = ((b->x[1] & ~0x800000) >> 16) | ((e + 129 + 55) << 7) | (b->x[1] << 16); - word1(rvp) = (b->x[0] >> 16) | (b->x[0] << 16); + /* The next two lines ignore swap of low- and high-order 2 bytes. */ + /* word0(rvp) = (b->x[1] & ~0x800000) | ((e + 129 + 55) << 23); */ + /* word1(rvp) = b->x[0]; */ + word0(rvp) = + ((b->x[1] & ~0x800000) >> 16) | ((e + 129 + 55) << 7) | (b->x[1] << 16); + word1(rvp) = (b->x[0] >> 16) | (b->x[0] << 16); #endif - Bfree(b MTa); - } + dtoa_bfree(b MTa); +} #endif /*!NO_HEX_FP}*/ - static int -dshift(Bigint *b, int p2) -{ - int rv = hi0bits(b->x[b->wds-1]) - 4; - if (p2 > 0) - rv -= p2; - return rv & kmask; - } +static int dtoa_dshift(Bigint *b, int p2) { + int rv = dtoa_hi0bits(b->x[b->wds - 1]) - 4; + if (p2 > 0) rv -= p2; + return rv & kmask; +} - static int -quorem(Bigint *b, Bigint *S) -{ - int n; - ULong *bx, *bxe, q, *sx, *sxe; +static int dtoa_quorem(Bigint *b, Bigint *S) { + int n; + ULong *bx, *bxe, q, *sx, *sxe; #ifdef ULLong - ULLong borrow, carry, y, ys; + ULLong borrow, carry, y, ys; #else - ULong borrow, carry, y, ys; + ULong borrow, carry, y, ys; #ifdef Pack_32 - ULong si, z, zs; + ULong si, z, zs; #endif #endif - n = S->wds; + n = S->wds; #ifdef DEBUG - /*debug*/ if (b->wds > n) - /*debug*/ Bug("oversize b in quorem"); + /*debug*/ if (b->wds > n) + /*debug*/ Bug("oversize b in dtoa_quorem"); #endif - if (b->wds < n) - return 0; - sx = S->x; - sxe = sx + --n; - bx = b->x; - bxe = bx + n; - q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ + if (b->wds < n) return 0; + sx = S->x; + sxe = sx + --n; + bx = b->x; + bxe = bx + n; + q = *bxe / (*sxe + 1); /* ensure q <= true quotient */ #ifdef DEBUG #ifdef NO_STRTOD_BIGCOMP - /*debug*/ if (q > 9) + /*debug*/ if (q > 9) #else - /* An oversized q is possible when quorem is called from bigcomp and */ - /* the input is near, e.g., twice the smallest denormalized number. */ - /*debug*/ if (q > 15) + /* An oversized q is possible when dtoa_quorem is called from dtoa_bigcomp and + */ + /* the input is near, e.g., twice the smallest denormalized number. */ + /*debug*/ if (q > 15) #endif - /*debug*/ Bug("oversized quotient in quorem"); + /*debug*/ Bug("oversized quotient in dtoa_quorem"); #endif - if (q) { - borrow = 0; - carry = 0; - do { + if (q) { + borrow = 0; + carry = 0; + do { #ifdef ULLong - ys = *sx++ * (ULLong)q + carry; - carry = ys >> 32; - y = *bx - (ys & FFFFFFFF) - borrow; - borrow = y >> 32 & (ULong)1; - *bx++ = y & FFFFFFFF; + ys = *sx++ * (ULLong)q + carry; + carry = ys >> 32; + y = *bx - (ys & FFFFFFFF) - borrow; + borrow = y >> 32 & (ULong)1; + *bx++ = y & FFFFFFFF; #else #ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) * q + carry; - zs = (si >> 16) * q + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*bx >> 16) - (zs & 0xffff) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(bx, z, y); + si = *sx++; + ys = (si & 0xffff) * q + carry; + zs = (si >> 16) * q + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*bx >> 16) - (zs & 0xffff) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(bx, z, y); #else - ys = *sx++ * q + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - *bx++ = y & 0xffff; + ys = *sx++ * q + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + *bx++ = y & 0xffff; #endif #endif - } - while(sx <= sxe); - if (!*bxe) { - bx = b->x; - while(--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - if (cmp(b, S) >= 0) { - q++; - borrow = 0; - carry = 0; - bx = b->x; - sx = S->x; - do { + } while (sx <= sxe); + if (!*bxe) { + bx = b->x; + while (--bxe > bx && !*bxe) --n; + b->wds = n; + } + } + if (dtoa_cmp(b, S) >= 0) { + q++; + borrow = 0; + carry = 0; + bx = b->x; + sx = S->x; + do { #ifdef ULLong - ys = *sx++ + carry; - carry = ys >> 32; - y = *bx - (ys & FFFFFFFF) - borrow; - borrow = y >> 32 & (ULong)1; - *bx++ = y & FFFFFFFF; + ys = *sx++ + carry; + carry = ys >> 32; + y = *bx - (ys & FFFFFFFF) - borrow; + borrow = y >> 32 & (ULong)1; + *bx++ = y & FFFFFFFF; #else #ifdef Pack_32 - si = *sx++; - ys = (si & 0xffff) + carry; - zs = (si >> 16) + (ys >> 16); - carry = zs >> 16; - y = (*bx & 0xffff) - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - z = (*bx >> 16) - (zs & 0xffff) - borrow; - borrow = (z & 0x10000) >> 16; - Storeinc(bx, z, y); + si = *sx++; + ys = (si & 0xffff) + carry; + zs = (si >> 16) + (ys >> 16); + carry = zs >> 16; + y = (*bx & 0xffff) - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + z = (*bx >> 16) - (zs & 0xffff) - borrow; + borrow = (z & 0x10000) >> 16; + Storeinc(bx, z, y); #else - ys = *sx++ + carry; - carry = ys >> 16; - y = *bx - (ys & 0xffff) - borrow; - borrow = (y & 0x10000) >> 16; - *bx++ = y & 0xffff; + ys = *sx++ + carry; + carry = ys >> 16; + y = *bx - (ys & 0xffff) - borrow; + borrow = (y & 0x10000) >> 16; + *bx++ = y & 0xffff; #endif #endif - } - while(sx <= sxe); - bx = b->x; - bxe = bx + n; - if (!*bxe) { - while(--bxe > bx && !*bxe) - --n; - b->wds = n; - } - } - return q; - } + } while (sx <= sxe); + bx = b->x; + bxe = bx + n; + if (!*bxe) { + while (--bxe > bx && !*bxe) --n; + b->wds = n; + } + } + return q; +} #if defined(Avoid_Underflow) || !defined(NO_STRTOD_BIGCOMP) /*{*/ - static double -sulp(U *x, BCinfo *bc) -{ - U u; - double rv; - int i; +static double dtoa_sulp(U *x, BCinfo *bc) { + U u; + double rv; + int i; - rv = ulp(x); - if (!bc->scale || (i = 2*P + 1 - ((word0(x) & Exp_mask) >> Exp_shift)) <= 0) - return rv; /* Is there an example where i <= 0 ? */ - word0(&u) = Exp_1 + (i << Exp_shift); - word1(&u) = 0; - return rv * u.d; - } + rv = ulp(x); + if (!bc->scale || (i = 2 * P + 1 - ((word0(x) & Exp_mask) >> Exp_shift)) <= 0) + return rv; /* Is there an example where i <= 0 ? */ + word0(&u) = Exp_1 + (i << Exp_shift); + word1(&u) = 0; + return rv * u.d; +} #endif /*}*/ #ifndef NO_STRTOD_BIGCOMP - static void -bigcomp(U *rv, const char *s0, BCinfo *bc MTd) -{ - Bigint *b, *d; - int b2, bbits, d2, dd, dig, dsign, i, j, nd, nd0, p2, p5, speccase; - dd = 0; /* TODO(jart): Why does compiler complain? */ +static void dtoa_bigcomp(U *rv, const char *s0, BCinfo *bc MTd) { + Bigint *b, *d; + int b2, bbits, d2, dd, dig, dsign, i, j, nd, nd0, p2, p5, speccase; + dd = 0; /* TODO(jart): Why does compiler complain? */ - dsign = bc->dsign; - nd = bc->nd; - nd0 = bc->nd0; - p5 = nd + bc->e0 - 1; - speccase = 0; + dsign = bc->dsign; + nd = bc->nd; + nd0 = bc->nd0; + p5 = nd + bc->e0 - 1; + speccase = 0; #ifndef Sudden_Underflow - if (rv->d == 0.) { /* special case: value near underflow-to-zero */ - /* threshold was rounded to zero */ - b = i2b(1 MTa); - p2 = Emin - P + 1; - bbits = 1; + if (rv->d == 0.) { /* special case: value near underflow-to-zero */ + /* threshold was rounded to zero */ + b = dtoa_i2b(1 MTa); + p2 = Emin - P + 1; + bbits = 1; #ifdef Avoid_Underflow - word0(rv) = (P+2) << Exp_shift; + word0(rv) = (P + 2) << Exp_shift; #else - word1(rv) = 1; + word1(rv) = 1; #endif - i = 0; + i = 0; #ifdef Honor_FLT_ROUNDS - if (bc->rounding == 1) + if (bc->rounding == 1) #endif - { - speccase = 1; - --p2; - dsign = 0; - goto have_i; - } - } - else + { + speccase = 1; + --p2; + dsign = 0; + goto have_i; + } + } else #endif - b = d2b(rv, &p2, &bbits MTa); + b = dtoa_d2b(rv, &p2, &bbits MTa); #ifdef Avoid_Underflow - p2 -= bc->scale; + p2 -= bc->scale; #endif - /* floor(log2(rv)) == bbits - 1 + p2 */ - /* Check for denormal case. */ - i = P - bbits; - if (i > (j = P - Emin - 1 + p2)) { + /* floor(log2(rv)) == bbits - 1 + p2 */ + /* Check for denormal case. */ + i = P - bbits; + if (i > (j = P - Emin - 1 + p2)) { #ifdef Sudden_Underflow - Bfree(b MTa); - b = i2b(1 MTa); - p2 = Emin; - i = P - 1; + dtoa_bfree(b MTa); + b = dtoa_i2b(1 MTa); + p2 = Emin; + i = P - 1; #ifdef Avoid_Underflow - word0(rv) = (1 + bc->scale) << Exp_shift; + word0(rv) = (1 + bc->scale) << Exp_shift; #else - word0(rv) = Exp_msk1; + word0(rv) = Exp_msk1; #endif - word1(rv) = 0; + word1(rv) = 0; #else - i = j; + i = j; #endif - } + } #ifdef Honor_FLT_ROUNDS - if (bc->rounding != 1) { - if (i > 0) - b = lshift(b, i MTa); - if (dsign) - b = increment(b MTa); - } - else + if (bc->rounding != 1) { + if (i > 0) b = dtoa_lshift(b, i MTa); + if (dsign) b = increment(b MTa); + } else #endif - { - b = lshift(b, ++i MTa); - b->x[0] |= 1; - } + { + b = dtoa_lshift(b, ++i MTa); + b->x[0] |= 1; + } #ifndef Sudden_Underflow - have_i: +have_i: #endif - p2 -= p5 + i; - d = i2b(1 MTa); - /* Arrange for convenient computation of quotients: - * shift left if necessary so divisor has 4 leading 0 bits. - */ - if (p5 > 0) - d = pow5mult(d, p5 MTa); - else if (p5 < 0) - b = pow5mult(b, -p5 MTa); - if (p2 > 0) { - b2 = p2; - d2 = 0; - } - else { - b2 = 0; - d2 = -p2; - } - i = dshift(d, d2); - if ((b2 += i) > 0) - b = lshift(b, b2 MTa); - if ((d2 += i) > 0) - d = lshift(d, d2 MTa); + p2 -= p5 + i; + d = dtoa_i2b(1 MTa); + /* Arrange for convenient computation of quotients: + * shift left if necessary so divisor has 4 leading 0 bits. + */ + if (p5 > 0) + d = dtoa_pow5mult(d, p5 MTa); + else if (p5 < 0) + b = dtoa_pow5mult(b, -p5 MTa); + if (p2 > 0) { + b2 = p2; + d2 = 0; + } else { + b2 = 0; + d2 = -p2; + } + i = dtoa_dshift(d, d2); + if ((b2 += i) > 0) b = dtoa_lshift(b, b2 MTa); + if ((d2 += i) > 0) d = dtoa_lshift(d, d2 MTa); - /* Now b/d = exactly half-way between the two floating-point values */ - /* on either side of the input string. Compute first digit of b/d. */ + /* Now b/d = exactly half-way between the two floating-point values */ + /* on either side of the input string. Compute first digit of b/d. */ - if (!(dig = quorem(b,d))) { - b = multadd(b, 10, 0 MTa); /* very unlikely */ - dig = quorem(b,d); - } + if (!(dig = dtoa_quorem(b, d))) { + b = dtoa_multadd(b, 10, 0 MTa); /* very unlikely */ + dig = dtoa_quorem(b, d); + } - /* Compare b/d with s0 */ + /* Compare b/d with s0 */ - for(i = 0; i < nd0; ) { - if ((dd = s0[i++] - '0' - dig)) - goto ret; - if (!b->x[0] && b->wds == 1) { - if (i < nd) - dd = 1; - goto ret; - } - b = multadd(b, 10, 0 MTa); - dig = quorem(b,d); - } - for(j = bc->dp1; i++ < nd;) { - if ((dd = s0[j++] - '0' - dig)) - goto ret; - if (!b->x[0] && b->wds == 1) { - if (i < nd) - dd = 1; - goto ret; - } - b = multadd(b, 10, 0 MTa); - dig = quorem(b,d); - } - if (dig > 0 || b->x[0] || b->wds > 1) - dd = -1; - ret: - Bfree(b MTa); - Bfree(d MTa); + for (i = 0; i < nd0;) { + if ((dd = s0[i++] - '0' - dig)) goto ret; + if (!b->x[0] && b->wds == 1) { + if (i < nd) dd = 1; + goto ret; + } + b = dtoa_multadd(b, 10, 0 MTa); + dig = dtoa_quorem(b, d); + } + for (j = bc->dp1; i++ < nd;) { + if ((dd = s0[j++] - '0' - dig)) goto ret; + if (!b->x[0] && b->wds == 1) { + if (i < nd) dd = 1; + goto ret; + } + b = dtoa_multadd(b, 10, 0 MTa); + dig = dtoa_quorem(b, d); + } + if (dig > 0 || b->x[0] || b->wds > 1) dd = -1; +ret: + dtoa_bfree(b MTa); + dtoa_bfree(d MTa); #ifdef Honor_FLT_ROUNDS - if (bc->rounding != 1) { - if (dd < 0) { - if (bc->rounding == 0) { - if (!dsign) - goto retlow1; - } - else if (dsign) - goto rethi1; - } - else if (dd > 0) { - if (bc->rounding == 0) { - if (dsign) - goto rethi1; - goto ret1; - } - if (!dsign) - goto rethi1; - dval(rv) += 2.*sulp(rv,bc); - } - else { - bc->inexact = 0; - if (dsign) - goto rethi1; - } - } - else + if (bc->rounding != 1) { + if (dd < 0) { + if (bc->rounding == 0) { + if (!dsign) goto retlow1; + } else if (dsign) + goto rethi1; + } else if (dd > 0) { + if (bc->rounding == 0) { + if (dsign) goto rethi1; + goto ret1; + } + if (!dsign) goto rethi1; + dval(rv) += 2. * dtoa_sulp(rv, bc); + } else { + bc->inexact = 0; + if (dsign) goto rethi1; + } + } else #endif - if (speccase) { - if (dd <= 0) - rv->d = 0.; - } - else if (dd < 0) { - if (!dsign) /* does not happen for round-near */ -retlow1: - dval(rv) -= sulp(rv,bc); - } - else if (dd > 0) { - if (dsign) { - rethi1: - dval(rv) += sulp(rv,bc); - } - } - else { - /* Exact half-way case: apply round-even rule. */ - if ((j = ((word0(rv) & Exp_mask) >> Exp_shift) - bc->scale) <= 0) { - i = 1 - j; - if (i <= 31) { - if (word1(rv) & (0x1 << i)) - goto odd; - } - else if (word0(rv) & (0x1 << (i-32))) - goto odd; - } - else if (word1(rv) & 1) { - odd: - if (dsign) - goto rethi1; - goto retlow1; - } - } + if (speccase) { + if (dd <= 0) rv->d = 0.; + } else if (dd < 0) { + if (!dsign) /* does not happen for round-near */ + retlow1: + dval(rv) -= dtoa_sulp(rv, bc); + } else if (dd > 0) { + if (dsign) { + rethi1: + dval(rv) += dtoa_sulp(rv, bc); + } + } else { + /* Exact half-way case: apply round-even rule. */ + if ((j = ((word0(rv) & Exp_mask) >> Exp_shift) - bc->scale) <= 0) { + i = 1 - j; + if (i <= 31) { + if (word1(rv) & (0x1 << i)) goto odd; + } else if (word0(rv) & (0x1 << (i - 32))) + goto odd; + } else if (word1(rv) & 1) { + odd: + if (dsign) goto rethi1; + goto retlow1; + } + } #ifdef Honor_FLT_ROUNDS - ret1: +ret1: #endif - return; - } + return; +} #endif /* NO_STRTOD_BIGCOMP */ - double -(strtod)(const char *s00, char **se) -{ - int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1; - int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign; - const char *s, *s0, *s1; - double aadj, aadj1; - Long L; - U aadj2, adj, rv, rv0; - ULong y, z; - BCinfo bc; - Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; +double(strtod)(const char *s00, char **se) { + int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1; + int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign; + const char *s, *s0, *s1; + double aadj, aadj1; + Long L; + U aadj2, adj, rv, rv0; + ULong y, z; + BCinfo bc; + Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; #ifdef USE_BF96 - ULLong bhi, blo, brv, t00, t01, t02, t10, t11, terv, tg, tlo, yz; - const BF96 *p10; - int bexact, erv; + ULLong bhi, blo, brv, t00, t01, t02, t10, t11, terv, tg, tlo, yz; + const BF96 *p10; + int bexact, erv; #endif #ifdef Avoid_Underflow - ULong Lsb, Lsb1; + ULong Lsb, Lsb1; #endif #ifdef SET_INEXACT - int oldinexact; + int oldinexact; #endif #ifndef NO_STRTOD_BIGCOMP - int req_bigcomp = 0; + int req_dtoa_bigcomp = 0; #endif #ifdef MULTIPLE_THREADS - ThInfo *TI = 0; + ThInfo *TI = 0; #endif #ifdef Honor_FLT_ROUNDS /*{*/ #ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ - bc.rounding = Flt_Rounds; -#else /*}{*/ - bc.rounding = 1; - switch(fegetround()) { - case FE_TOWARDZERO: bc.rounding = 0; break; - case FE_UPWARD: bc.rounding = 2; break; - case FE_DOWNWARD: bc.rounding = 3; - } + bc.rounding = Flt_Rounds; +#else /*}{*/ + bc.rounding = 1; + switch (fegetround()) { + case FE_TOWARDZERO: + bc.rounding = 0; + break; + case FE_UPWARD: + bc.rounding = 2; + break; + case FE_DOWNWARD: + bc.rounding = 3; + } #endif /*}}*/ #endif /*}*/ #ifdef USE_LOCALE - const char *s2; + const char *s2; #endif - sign = nz0 = nz1 = nz = bc.dplen = bc.uflchk = 0; - dval(&rv) = 0.; - for(s = s00;;s++) switch(*s) { - case '-': - sign = 1; - /* no break */ - case '+': - if (*++s) - goto break2; - /* no break */ - case 0: - goto ret0; - case '\t': - case '\n': - case '\v': - case '\f': - case '\r': - case ' ': - continue; - default: - goto break2; - } - break2: - if (*s == '0') { + sign = nz0 = nz1 = nz = bc.dplen = bc.uflchk = 0; + dval(&rv) = 0.; + for (s = s00;; s++) switch (*s) { + case '-': + sign = 1; + /* no break */ + case '+': + if (*++s) goto break2; + /* no break */ + case 0: + goto ret0; + case '\t': + case '\n': + case '\v': + case '\f': + case '\r': + case ' ': + continue; + default: + goto break2; + } +break2: + if (*s == '0') { #ifndef NO_HEX_FP /*{*/ - switch(s[1]) { - case 'x': - case 'X': + switch (s[1]) { + case 'x': + case 'X': #ifdef Honor_FLT_ROUNDS - gethex(&s, &rv, bc.rounding, sign MTb); + gethex(&s, &rv, bc.rounding, sign MTb); #else - gethex(&s, &rv, 1, sign MTb); + gethex(&s, &rv, 1, sign MTb); #endif - goto ret; - } + goto ret; + } #endif /*}*/ - nz0 = 1; - while(*++s == '0') ; - if (!*s) - goto ret; - } - s0 = s; - nd = nf = 0; + nz0 = 1; + while (*++s == '0') + ; + if (!*s) goto ret; + } + s0 = s; + nd = nf = 0; #ifdef USE_BF96 - yz = 0; - for(; (c = *s) >= '0' && c <= '9'; nd++, s++) - if (nd < 19) - yz = 10*yz + c - '0'; + yz = 0; + for (; (c = *s) >= '0' && c <= '9'; nd++, s++) + if (nd < 19) yz = 10 * yz + c - '0'; #else - y = z = 0; - for(; (c = *s) >= '0' && c <= '9'; nd++, s++) - if (nd < 9) - y = 10*y + c - '0'; - else if (nd < DBL_DIG + 2) - z = 10*z + c - '0'; + y = z = 0; + for (; (c = *s) >= '0' && c <= '9'; nd++, s++) + if (nd < 9) + y = 10 * y + c - '0'; + else if (nd < DBL_DIG + 2) + z = 10 * z + c - '0'; #endif - nd0 = nd; - bc.dp0 = bc.dp1 = s - s0; - for(s1 = s; s1 > s0 && *--s1 == '0'; ) - ++nz1; + nd0 = nd; + bc.dp0 = bc.dp1 = s - s0; + for (s1 = s; s1 > s0 && *--s1 == '0';) ++nz1; #ifdef USE_LOCALE - s1 = localeconv()->decimal_point; - if (c == *s1) { - c = '.'; - if (*++s1) { - s2 = s; - for(;;) { - if (*++s2 != *s1) { - c = 0; - break; - } - if (!*++s1) { - s = s2; - break; - } - } - } - } + s1 = localeconv()->decimal_point; + if (c == *s1) { + c = '.'; + if (*++s1) { + s2 = s; + for (;;) { + if (*++s2 != *s1) { + c = 0; + break; + } + if (!*++s1) { + s = s2; + break; + } + } + } + } #endif - if (c == '.') { - c = *++s; - bc.dp1 = s - s0; - bc.dplen = bc.dp1 - bc.dp0; - if (!nd) { - for(; c == '0'; c = *++s) - nz++; - if (c > '0' && c <= '9') { - bc.dp0 = s0 - s; - bc.dp1 = bc.dp0 + bc.dplen; - s0 = s; - nf += nz; - nz = 0; - goto have_dig; - } - goto dig_done; - } - for(; c >= '0' && c <= '9'; c = *++s) { - have_dig: - nz++; - if (c -= '0') { - nf += nz; - i = 1; + if (c == '.') { + c = *++s; + bc.dp1 = s - s0; + bc.dplen = bc.dp1 - bc.dp0; + if (!nd) { + for (; c == '0'; c = *++s) nz++; + if (c > '0' && c <= '9') { + bc.dp0 = s0 - s; + bc.dp1 = bc.dp0 + bc.dplen; + s0 = s; + nf += nz; + nz = 0; + goto have_dig; + } + goto dig_done; + } + for (; c >= '0' && c <= '9'; c = *++s) { + have_dig: + nz++; + if (c -= '0') { + nf += nz; + i = 1; #ifdef USE_BF96 - for(; i < nz; ++i) { - if (++nd <= 19) - yz *= 10; - } - if (++nd <= 19) - yz = 10*yz + c; + for (; i < nz; ++i) { + if (++nd <= 19) yz *= 10; + } + if (++nd <= 19) yz = 10 * yz + c; #else - for(; i < nz; ++i) { - if (nd++ < 9) - y *= 10; - else if (nd <= DBL_DIG + 2) - z *= 10; - } - if (nd++ < 9) - y = 10*y + c; - else if (nd <= DBL_DIG + 2) - z = 10*z + c; + for (; i < nz; ++i) { + if (nd++ < 9) + y *= 10; + else if (nd <= DBL_DIG + 2) + z *= 10; + } + if (nd++ < 9) + y = 10 * y + c; + else if (nd <= DBL_DIG + 2) + z = 10 * z + c; #endif - nz = nz1 = 0; - } - } - } - dig_done: - e = 0; - if (c == 'e' || c == 'E') { - if (!nd && !nz && !nz0) { - goto ret0; - } - s00 = s; - esign = 0; - switch(c = *++s) { - case '-': - esign = 1; - case '+': - c = *++s; - } - if (c >= '0' && c <= '9') { - while(c == '0') - c = *++s; - if (c > '0' && c <= '9') { - L = c - '0'; - s1 = s; - while((c = *++s) >= '0' && c <= '9') - L = 10*L + c - '0'; - if (s - s1 > 8 || L > 19999) - /* Avoid confusion from exponents - * so large that e might overflow. - */ - e = 19999; /* safe for 16 bit ints */ - else - e = (int)L; - if (esign) - e = -e; - } - else - e = 0; - } - else - s = s00; - } - if (!nd) { - if (!nz && !nz0) { + nz = nz1 = 0; + } + } + } +dig_done: + e = 0; + if (c == 'e' || c == 'E') { + if (!nd && !nz && !nz0) { + goto ret0; + } + s00 = s; + esign = 0; + switch (c = *++s) { + case '-': + esign = 1; + case '+': + c = *++s; + } + if (c >= '0' && c <= '9') { + while (c == '0') c = *++s; + if (c > '0' && c <= '9') { + L = c - '0'; + s1 = s; + while ((c = *++s) >= '0' && c <= '9') L = 10 * L + c - '0'; + if (s - s1 > 8 || L > 19999) + /* Avoid confusion from exponents + * so large that e might overflow. + */ + e = 19999; /* safe for 16 bit ints */ + else + e = (int)L; + if (esign) e = -e; + } else + e = 0; + } else + s = s00; + } + if (!nd) { + if (!nz && !nz0) { #ifdef INFNAN_CHECK /*{*/ - /* Check for Nan and Infinity */ - if (!bc.dplen) - switch(c) { - case 'i': - case 'I': - if (match(&s,"nf")) { - --s; - if (!match(&s,"inity")) - ++s; - word0(&rv) = 0x7ff00000; - word1(&rv) = 0; - goto ret; - } - break; - case 'n': - case 'N': - if (match(&s, "an")) { - word0(&rv) = NAN_WORD0; - word1(&rv) = NAN_WORD1; + /* Check for Nan and Infinity */ + if (!bc.dplen) switch (c) { + case 'i': + case 'I': + if (dtoa_match(&s, "nf")) { + --s; + if (!dtoa_match(&s, "inity")) ++s; + word0(&rv) = 0x7ff00000; + word1(&rv) = 0; + goto ret; + } + break; + case 'n': + case 'N': + if (dtoa_match(&s, "an")) { + word0(&rv) = NAN_WORD0; + word1(&rv) = NAN_WORD1; #ifndef No_Hex_NaN - if (*s == '(') /*)*/ - hexnan(&rv, &s); + if (*s == '(') /*)*/ + dtoa_hexnan(&rv, &s); #endif - goto ret; - } - } + goto ret; + } + } #endif /*} INFNAN_CHECK */ - ret0: - s = s00; - sign = 0; - } - goto ret; - } - bc.e0 = e1 = e -= nf; + ret0: + s = s00; + sign = 0; + } + goto ret; + } + bc.e0 = e1 = e -= nf; - /* Now we have nd0 digits, starting at s0, followed by a - * decimal point, followed by nd-nd0 digits. The number we're - * after is the integer represented by those digits times - * 10**e */ + /* Now we have nd0 digits, starting at s0, followed by a + * decimal point, followed by nd-nd0 digits. The number we're + * after is the integer represented by those digits times + * 10**e */ - if (!nd0) - nd0 = nd; + if (!nd0) nd0 = nd; #ifndef USE_BF96 - k = nd < DBL_DIG + 2 ? nd : DBL_DIG + 2; - dval(&rv) = y; - if (k > 9) { + k = nd < DBL_DIG + 2 ? nd : DBL_DIG + 2; + dval(&rv) = y; + if (k > 9) { #ifdef SET_INEXACT - if (k > DBL_DIG) - oldinexact = get_inexact(); + if (k > DBL_DIG) oldinexact = get_inexact(); #endif - dval(&rv) = tens[k - 9] * dval(&rv) + z; - } + dval(&rv) = kDtoaTens[k - 9] * dval(&rv) + z; + } #endif - bd0 = 0; - if (nd <= DBL_DIG + bd0 = 0; + if (nd <= DBL_DIG #ifndef RND_PRODQUOT #ifndef Honor_FLT_ROUNDS - && Flt_Rounds == 1 + && Flt_Rounds == 1 #endif #endif - ) { + ) { #ifdef USE_BF96 - dval(&rv) = yz; + dval(&rv) = yz; #endif - if (!e) - goto ret; + if (!e) goto ret; #ifndef ROUND_BIASED_without_Round_Up - if (e > 0) { - if (e <= Ten_pmax) { + if (e > 0) { + if (e <= Ten_pmax) { #ifdef SET_INEXACT - bc.inexact = 0; - oldinexact = 1; + bc.inexact = 0; + oldinexact = 1; #endif #ifdef VAX - goto vax_ovfl_check; + goto vax_ovfl_check; #else #ifdef Honor_FLT_ROUNDS - /* round correctly FLT_ROUNDS = 2 or 3 */ - if (sign) { - rv.d = -rv.d; - sign = 0; - } + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv.d = -rv.d; + sign = 0; + } #endif - /* rv = */ rounded_product(dval(&rv), tens[e]); - goto ret; + /* rv = */ rounded_product(dval(&rv), kDtoaTens[e]); + goto ret; #endif - } - i = DBL_DIG - nd; - if (e <= Ten_pmax + i) { - /* A fancier test would sometimes let us do - * this for larger i values. - */ + } + i = DBL_DIG - nd; + if (e <= Ten_pmax + i) { + /* A fancier test would sometimes let us do + * this for larger i values. + */ #ifdef SET_INEXACT - bc.inexact = 0; - oldinexact = 1; + bc.inexact = 0; + oldinexact = 1; #endif #ifdef Honor_FLT_ROUNDS - /* round correctly FLT_ROUNDS = 2 or 3 */ - if (sign) { - rv.d = -rv.d; - sign = 0; - } + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv.d = -rv.d; + sign = 0; + } #endif - e -= i; - dval(&rv) *= tens[i]; + e -= i; + dval(&rv) *= kDtoaTens[i]; #ifdef VAX - /* VAX exponent range is so narrow we must - * worry about overflow here... - */ - vax_ovfl_check: - word0(&rv) -= P*Exp_msk1; - /* rv = */ rounded_product(dval(&rv), tens[e]); - if ((word0(&rv) & Exp_mask) - > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) - goto ovfl; - word0(&rv) += P*Exp_msk1; + /* VAX exponent range is so narrow we must + * worry about overflow here... + */ + vax_ovfl_check: + word0(&rv) -= P * Exp_msk1; + /* rv = */ rounded_product(dval(&rv), kDtoaTens[e]); + if ((word0(&rv) & Exp_mask) > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P)) + goto ovfl; + word0(&rv) += P * Exp_msk1; #else - /* rv = */ rounded_product(dval(&rv), tens[e]); + /* rv = */ rounded_product(dval(&rv), kDtoaTens[e]); #endif - goto ret; - } - } + goto ret; + } + } #ifndef Inaccurate_Divide - else if (e >= -Ten_pmax) { + else if (e >= -Ten_pmax) { #ifdef SET_INEXACT - bc.inexact = 0; - oldinexact = 1; + bc.inexact = 0; + oldinexact = 1; #endif #ifdef Honor_FLT_ROUNDS - /* round correctly FLT_ROUNDS = 2 or 3 */ - if (sign) { - rv.d = -rv.d; - sign = 0; - } + /* round correctly FLT_ROUNDS = 2 or 3 */ + if (sign) { + rv.d = -rv.d; + sign = 0; + } #endif - /* rv = */ rounded_quotient(dval(&rv), tens[-e]); - goto ret; - } + /* rv = */ rounded_quotient(dval(&rv), kDtoaTens[-e]); + goto ret; + } #endif #endif /* ROUND_BIASED_without_Round_Up */ - } + } #ifdef USE_BF96 - k = nd < 19 ? nd : 19; + k = nd < 19 ? nd : 19; #endif - e1 += nd - k; /* scale factor = 10^e1 */ + e1 += nd - k; /* scale factor = 10^e1 */ #ifdef IEEE_Arith #ifdef SET_INEXACT - bc.inexact = 1; + bc.inexact = 1; #ifndef USE_BF96 - if (k <= DBL_DIG) + if (k <= DBL_DIG) #endif - oldinexact = get_inexact(); + oldinexact = get_inexact(); #endif #ifdef Honor_FLT_ROUNDS - if (bc.rounding >= 2) { - if (sign) - bc.rounding = bc.rounding == 2 ? 0 : 2; - else - if (bc.rounding != 2) - bc.rounding = 0; - } + if (bc.rounding >= 2) { + if (sign) + bc.rounding = bc.rounding == 2 ? 0 : 2; + else if (bc.rounding != 2) + bc.rounding = 0; + } #endif #endif /*IEEE_Arith*/ #ifdef USE_BF96 /*{*/ - Debug(++dtoa_stats[0]); - i = e1 + 342; - if (i < 0) - goto undfl; - if (i > 650) - goto ovfl; - p10 = &pten[i]; - brv = yz; - /* shift brv left, with i = number of bits shifted */ - i = 0; - if (!(brv & 0xffffffff00000000ull)) { - i = 32; - brv <<= 32; - } - if (!(brv & 0xffff000000000000ull)) { - i += 16; - brv <<= 16; - } - if (!(brv & 0xff00000000000000ull)) { - i += 8; - brv <<= 8; - } - if (!(brv & 0xf000000000000000ull)) { - i += 4; - brv <<= 4; - } - if (!(brv & 0xc000000000000000ull)) { - i += 2; - brv <<= 2; - } - if (!(brv & 0x8000000000000000ull)) { - i += 1; - brv <<= 1; - } - erv = (64 + 0x3fe) + p10->e - i; - if (erv <= 0 && nd > 19) - goto many_digits; /* denormal: may need to look at all digits */ - bhi = brv >> 32; - blo = brv & 0xffffffffull; - /* Unsigned 32-bit ints lie in [0,2^32-1] and */ - /* unsigned 64-bit ints lie in [0, 2^64-1]. The product of two unsigned */ - /* 32-bit ints is <= 2^64 - 2*2^32-1 + 1 = 2^64 - 1 - 2*(2^32 - 1), so */ - /* we can add two unsigned 32-bit ints to the product of two such ints, */ - /* and 64 bits suffice to contain the result. */ - t01 = bhi * p10->b1; - t10 = blo * p10->b0 + (t01 & 0xffffffffull); - t00 = bhi * p10->b0 + (t01 >> 32) + (t10 >> 32); - if (t00 & 0x8000000000000000ull) { - if ((t00 & 0x3ff) && (~t00 & 0x3fe)) { /* unambiguous result? */ - if (nd > 19 && ((t00 + (1< 650) goto ovfl; + p10 = &kDtoaPten[i]; + brv = yz; + /* shift brv left, with i = number of bits shifted */ + i = 0; + if (!(brv & 0xffffffff00000000ull)) { + i = 32; + brv <<= 32; + } + if (!(brv & 0xffff000000000000ull)) { + i += 16; + brv <<= 16; + } + if (!(brv & 0xff00000000000000ull)) { + i += 8; + brv <<= 8; + } + if (!(brv & 0xf000000000000000ull)) { + i += 4; + brv <<= 4; + } + if (!(brv & 0xc000000000000000ull)) { + i += 2; + brv <<= 2; + } + if (!(brv & 0x8000000000000000ull)) { + i += 1; + brv <<= 1; + } + erv = (64 + 0x3fe) + p10->e - i; + if (erv <= 0 && nd > 19) + goto many_digits; /* denormal: may need to look at all digits */ + bhi = brv >> 32; + blo = brv & 0xffffffffull; + /* Unsigned 32-bit ints lie in [0,2^32-1] and */ + /* unsigned 64-bit ints lie in [0, 2^64-1]. The product of two unsigned */ + /* 32-bit ints is <= 2^64 - 2*2^32-1 + 1 = 2^64 - 1 - 2*(2^32 - 1), so */ + /* we can add two unsigned 32-bit ints to the product of two such ints, */ + /* and 64 bits suffice to contain the result. */ + t01 = bhi * p10->b1; + t10 = blo * p10->b0 + (t01 & 0xffffffffull); + t00 = bhi * p10->b0 + (t01 >> 32) + (t10 >> 32); + if (t00 & 0x8000000000000000ull) { + if ((t00 & 0x3ff) && (~t00 & 0x3fe)) { /* unambiguous result? */ + if (nd > 19 && ((t00 + (1 << i) + 2) & 0x400) ^ (t00 & 0x400)) + goto many_digits; + if (erv <= 0) goto denormal; #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto noround; - case 2: goto roundup; - } + switch (bc.rounding) { + case 0: + goto noround; + case 2: + goto roundup; + } #endif - if (t00 & 0x400 && t00 & 0xbff) - goto roundup; - goto noround; - } - } - else { - if ((t00 & 0x1ff) && (~t00 & 0x1fe)) { /* unambiguous result? */ - if (nd > 19 && ((t00 + (1< 19 && ((t00 + (1 << i) + 2) & 0x200) ^ (t00 & 0x200)) + goto many_digits; + if (erv <= 1) goto denormal1; #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto noround1; - case 2: goto roundup1; - } + switch (bc.rounding) { + case 0: + goto noround1; + case 2: + goto roundup1; + } #endif - if (t00 & 0x200) - goto roundup1; - goto noround1; - } - } - /* 3 multiplies did not suffice; try a 96-bit approximation */ - Debug(++dtoa_stats[1]); - t02 = bhi * p10->b2; - t11 = blo * p10->b1 + (t02 & 0xffffffffull); - bexact = 1; - if (e1 < 0 || e1 > 41 || (t10 | t11) & 0xffffffffull || nd > 19) - bexact = 0; - tlo = (t10 & 0xffffffffull) + (t02 >> 32) + (t11 >> 32); - if (!bexact && (tlo + 0x10) >> 32 > tlo >> 32) - goto many_digits; - t00 += tlo >> 32; - if (t00 & 0x8000000000000000ull) { - if (erv <= 0) { /* denormal result */ - if (nd >= 20 || !((tlo & 0xfffffff0) | (t00 & 0x3ff))) - goto many_digits; - denormal: - if (erv <= -52) { + if (t00 & 0x200) goto roundup1; + goto noround1; + } + } + /* 3 multiplies did not suffice; try a 96-bit approximation */ + Debug(++dtoa_stats[1]); + t02 = bhi * p10->b2; + t11 = blo * p10->b1 + (t02 & 0xffffffffull); + bexact = 1; + if (e1 < 0 || e1 > 41 || (t10 | t11) & 0xffffffffull || nd > 19) bexact = 0; + tlo = (t10 & 0xffffffffull) + (t02 >> 32) + (t11 >> 32); + if (!bexact && (tlo + 0x10) >> 32 > tlo >> 32) goto many_digits; + t00 += tlo >> 32; + if (t00 & 0x8000000000000000ull) { + if (erv <= 0) { /* denormal result */ + if (nd >= 20 || !((tlo & 0xfffffff0) | (t00 & 0x3ff))) goto many_digits; + denormal: + if (erv <= -52) { #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto undfl; - case 2: goto tiniest; - } + switch (bc.rounding) { + case 0: + goto undfl; + case 2: + goto tiniest; + } #endif - if (erv < -52 || !(t00 & 0x7fffffffffffffffull)) - goto undfl; - goto tiniest; - } - tg = 1ull << (11 - erv); - t00 &= ~(tg - 1); /* clear low bits */ + if (erv < -52 || !(t00 & 0x7fffffffffffffffull)) goto undfl; + goto tiniest; + } + tg = 1ull << (11 - erv); + t00 &= ~(tg - 1); /* clear low bits */ #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto noround_den; - case 2: goto roundup_den; - } + switch (bc.rounding) { + case 0: + goto noround_den; + case 2: + goto roundup_den; + } #endif - if (t00 & tg) { + if (t00 & tg) { #ifdef Honor_FLT_ROUNDS - roundup_den: + roundup_den: #endif - t00 += tg << 1; - if (!(t00 & 0x8000000000000000ull)) { - if (++erv > 0) - goto smallest_normal; - t00 = 0x8000000000000000ull; - } - } + t00 += tg << 1; + if (!(t00 & 0x8000000000000000ull)) { + if (++erv > 0) goto smallest_normal; + t00 = 0x8000000000000000ull; + } + } #ifdef Honor_FLT_ROUNDS - noround_den: + noround_den: #endif - LLval(&rv) = t00 >> (12 - erv); - Set_errno(erange); - goto ret; - } - if (bexact) { + LLval(&rv) = t00 >> (12 - erv); + Set_errno(erange); + goto ret; + } + if (bexact) { #ifdef SET_INEXACT - if (!(t00 & 0x7ff) && !(tlo & 0xffffffffull)) { - bc.inexact = 0; - goto noround; - } + if (!(t00 & 0x7ff) && !(tlo & 0xffffffffull)) { + bc.inexact = 0; + goto noround; + } #endif #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 2: - if (t00 & 0x7ff) - goto roundup; - case 0: goto noround; - } + switch (bc.rounding) { + case 2: + if (t00 & 0x7ff) goto roundup; + case 0: + goto noround; + } #endif - if (t00 & 0x400 && (tlo & 0xffffffff) | (t00 & 0xbff)) - goto roundup; - goto noround; - } - if ((tlo & 0xfffffff0) | (t00 & 0x3ff) - && (nd <= 19 || ((t00 + (1ull << i)) & 0xfffffffffffffc00ull) - == (t00 & 0xfffffffffffffc00ull))) { - /* Unambiguous result. */ - /* If nd > 19, then incrementing the 19th digit */ - /* does not affect rv. */ + if (t00 & 0x400 && (tlo & 0xffffffff) | (t00 & 0xbff)) goto roundup; + goto noround; + } + if ((tlo & 0xfffffff0) | (t00 & 0x3ff) && + (nd <= 19 || ((t00 + (1ull << i)) & 0xfffffffffffffc00ull) == + (t00 & 0xfffffffffffffc00ull))) { + /* Unambiguous result. */ + /* If nd > 19, then incrementing the 19th digit */ + /* does not affect rv. */ #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto noround; - case 2: goto roundup; - } + switch (bc.rounding) { + case 0: + goto noround; + case 2: + goto roundup; + } #endif - if (t00 & 0x400) { /* round up */ - roundup: - t00 += 0x800; - if (!(t00 & 0x8000000000000000ull)) { - /* rounded up to a power of 2 */ - if (erv >= 0x7fe) - goto ovfl; - terv = erv + 1; - LLval(&rv) = terv << 52; - goto ret; - } - } - noround: - if (erv >= 0x7ff) - goto ovfl; - terv = erv; - LLval(&rv) = (terv << 52) | ((t00 & 0x7ffffffffffff800ull) >> 11); - goto ret; - } - } - else { - if (erv <= 1) { /* denormal result */ - if (nd >= 20 || !((tlo & 0xfffffff0) | (t00 & 0x1ff))) - goto many_digits; - denormal1: - if (erv <= -51) { + if (t00 & 0x400) { /* round up */ + roundup: + t00 += 0x800; + if (!(t00 & 0x8000000000000000ull)) { + /* rounded up to a power of 2 */ + if (erv >= 0x7fe) goto ovfl; + terv = erv + 1; + LLval(&rv) = terv << 52; + goto ret; + } + } + noround: + if (erv >= 0x7ff) goto ovfl; + terv = erv; + LLval(&rv) = (terv << 52) | ((t00 & 0x7ffffffffffff800ull) >> 11); + goto ret; + } + } else { + if (erv <= 1) { /* denormal result */ + if (nd >= 20 || !((tlo & 0xfffffff0) | (t00 & 0x1ff))) goto many_digits; + denormal1: + if (erv <= -51) { #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto undfl; - case 2: goto tiniest; - } + switch (bc.rounding) { + case 0: + goto undfl; + case 2: + goto tiniest; + } #endif - if (erv < -51 || !(t00 & 0x3fffffffffffffffull)) - goto undfl; - tiniest: - LLval(&rv) = 1; - Set_errno(erange); - goto ret; - } - tg = 1ull << (11 - erv); + if (erv < -51 || !(t00 & 0x3fffffffffffffffull)) goto undfl; + tiniest: + LLval(&rv) = 1; + Set_errno(erange); + goto ret; + } + tg = 1ull << (11 - erv); #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto noround1_den; - case 2: goto roundup1_den; - } + switch (bc.rounding) { + case 0: + goto noround1_den; + case 2: + goto roundup1_den; + } #endif - if (t00 & tg) { + if (t00 & tg) { #ifdef Honor_FLT_ROUNDS - roundup1_den: + roundup1_den: #endif - if (0x8000000000000000ull & (t00 += (tg<<1)) && erv == 1) { + if (0x8000000000000000ull & (t00 += (tg << 1)) && erv == 1) { - smallest_normal: - LLval(&rv) = 0x0010000000000000ull; - goto ret; - } - } + smallest_normal: + LLval(&rv) = 0x0010000000000000ull; + goto ret; + } + } #ifdef Honor_FLT_ROUNDS - noround1_den: + noround1_den: #endif - if (erv <= -52) - goto undfl; - LLval(&rv) = t00 >> (12 - erv); - Set_errno(erange); - goto ret; - } - if (bexact) { + if (erv <= -52) goto undfl; + LLval(&rv) = t00 >> (12 - erv); + Set_errno(erange); + goto ret; + } + if (bexact) { #ifdef SET_INEXACT - if (!(t00 & 0x3ff) && !(tlo & 0xffffffffull)) { - bc.inexact = 0; - goto noround1; - } + if (!(t00 & 0x3ff) && !(tlo & 0xffffffffull)) { + bc.inexact = 0; + goto noround1; + } #endif #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 2: - if (t00 & 0x3ff) - goto roundup1; - case 0: goto noround1; - } + switch (bc.rounding) { + case 2: + if (t00 & 0x3ff) goto roundup1; + case 0: + goto noround1; + } #endif - if (t00 & 0x200 && (t00 & 0x5ff || tlo)) - goto roundup1; - goto noround1; - } - if ((tlo & 0xfffffff0) | (t00 & 0x1ff) - && (nd <= 19 || ((t00 + (1ull << i)) & 0x7ffffffffffffe00ull) - == (t00 & 0x7ffffffffffffe00ull))) { - /* Unambiguous result. */ + if (t00 & 0x200 && (t00 & 0x5ff || tlo)) goto roundup1; + goto noround1; + } + if ((tlo & 0xfffffff0) | (t00 & 0x1ff) && + (nd <= 19 || ((t00 + (1ull << i)) & 0x7ffffffffffffe00ull) == + (t00 & 0x7ffffffffffffe00ull))) { + /* Unambiguous result. */ #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: goto noround1; - case 2: goto roundup1; - } + switch (bc.rounding) { + case 0: + goto noround1; + case 2: + goto roundup1; + } #endif - if (t00 & 0x200) { /* round up */ - roundup1: - t00 += 0x400; - if (!(t00 & 0x4000000000000000ull)) { - /* rounded up to a power of 2 */ - if (erv >= 0x7ff) - goto ovfl; - terv = erv; - LLval(&rv) = terv << 52; - goto ret; - } - } - noround1: - if (erv >= 0x800) - goto ovfl; - terv = erv - 1; - LLval(&rv) = (terv << 52) | ((t00 & 0x3ffffffffffffc00ull) >> 10); - goto ret; - } - } - many_digits: - Debug(++dtoa_stats[2]); - if (nd > 17) { - if (nd > 18) { - yz /= 100; - e1 += 2; - } - else { - yz /= 10; - e1 += 1; - } - y = yz / 100000000; - } - else if (nd > 9) { - i = nd - 9; - y = (yz >> i) / pfive[i-1]; - } - else - y = yz; - dval(&rv) = yz; + if (t00 & 0x200) { /* round up */ + roundup1: + t00 += 0x400; + if (!(t00 & 0x4000000000000000ull)) { + /* rounded up to a power of 2 */ + if (erv >= 0x7ff) goto ovfl; + terv = erv; + LLval(&rv) = terv << 52; + goto ret; + } + } + noround1: + if (erv >= 0x800) goto ovfl; + terv = erv - 1; + LLval(&rv) = (terv << 52) | ((t00 & 0x3ffffffffffffc00ull) >> 10); + goto ret; + } + } +many_digits: + Debug(++dtoa_stats[2]); + if (nd > 17) { + if (nd > 18) { + yz /= 100; + e1 += 2; + } else { + yz /= 10; + e1 += 1; + } + y = yz / 100000000; + } else if (nd > 9) { + i = nd - 9; + y = (yz >> i) / kDtoaPfive[i - 1]; + } else + y = yz; + dval(&rv) = yz; #endif /*}*/ #ifdef IEEE_Arith #ifdef Avoid_Underflow - bc.scale = 0; + bc.scale = 0; #endif #endif /*IEEE_Arith*/ - /* Get starting approximation = rv * 10**e1 */ + /* Get starting approximation = rv * 10**e1 */ - if (e1 > 0) { - if ((i = e1 & 15)) - dval(&rv) *= tens[i]; - if (e1 &= ~15) { - if (e1 > DBL_MAX_10_EXP) { - ovfl: - /* Can't trust HUGE_VAL */ + if (e1 > 0) { + if ((i = e1 & 15)) dval(&rv) *= kDtoaTens[i]; + if (e1 &= ~15) { + if (e1 > DBL_MAX_10_EXP) { + ovfl: + /* Can't trust HUGE_VAL */ #ifdef IEEE_Arith #ifdef Honor_FLT_ROUNDS - switch(bc.rounding) { - case 0: /* toward 0 */ - case 3: /* toward -infinity */ - word0(&rv) = Big0; - word1(&rv) = Big1; - break; - default: - word0(&rv) = Exp_mask; - word1(&rv) = 0; - } -#else /*Honor_FLT_ROUNDS*/ - word0(&rv) = Exp_mask; - word1(&rv) = 0; + switch (bc.rounding) { + case 0: /* toward 0 */ + case 3: /* toward -infinity */ + word0(&rv) = Big0; + word1(&rv) = Big1; + break; + default: + word0(&rv) = Exp_mask; + word1(&rv) = 0; + } +#else /*Honor_FLT_ROUNDS*/ + word0(&rv) = Exp_mask; + word1(&rv) = 0; #endif /*Honor_FLT_ROUNDS*/ #ifdef SET_INEXACT - /* set overflow bit */ - dval(&rv0) = 1e300; - dval(&rv0) *= dval(&rv0); + /* set overflow bit */ + dval(&rv0) = 1e300; + dval(&rv0) *= dval(&rv0); #endif -#else /*IEEE_Arith*/ - word0(&rv) = Big0; - word1(&rv) = Big1; +#else /*IEEE_Arith*/ + word0(&rv) = Big0; + word1(&rv) = Big1; #endif /*IEEE_Arith*/ - range_err: - if (bd0) { - Bfree(bb MTb); - Bfree(bd MTb); - Bfree(bs MTb); - Bfree(bd0 MTb); - Bfree(delta MTb); - } - Set_errno(erange); - goto ret; - } - e1 >>= 4; - for(j = 0; e1 > 1; j++, e1 >>= 1) - if (e1 & 1) - dval(&rv) *= bigtens[j]; - /* The last multiplication could overflow. */ - word0(&rv) -= P*Exp_msk1; - dval(&rv) *= bigtens[j]; - if ((z = word0(&rv) & Exp_mask) - > Exp_msk1*(DBL_MAX_EXP+Bias-P)) - goto ovfl; - if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) { - /* set to largest number */ - /* (Can't trust DBL_MAX) */ - word0(&rv) = Big0; - word1(&rv) = Big1; - } - else - word0(&rv) += P*Exp_msk1; - } - } - else if (e1 < 0) { - e1 = -e1; - if ((i = e1 & 15)) - dval(&rv) /= tens[i]; - if (e1 >>= 4) { - if (e1 >= 1u << n_bigtens) - goto undfl; + range_err: + if (bd0) { + dtoa_bfree(bb MTb); + dtoa_bfree(bd MTb); + dtoa_bfree(bs MTb); + dtoa_bfree(bd0 MTb); + dtoa_bfree(delta MTb); + } + Set_errno(erange); + goto ret; + } + e1 >>= 4; + for (j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) dval(&rv) *= kDtoaBigTens[j]; + /* The last multiplication could overflow. */ + word0(&rv) -= P * Exp_msk1; + dval(&rv) *= kDtoaBigTens[j]; + if ((z = word0(&rv) & Exp_mask) > Exp_msk1 * (DBL_MAX_EXP + Bias - P)) + goto ovfl; + if (z > Exp_msk1 * (DBL_MAX_EXP + Bias - 1 - P)) { + /* set to largest number */ + /* (Can't trust DBL_MAX) */ + word0(&rv) = Big0; + word1(&rv) = Big1; + } else + word0(&rv) += P * Exp_msk1; + } + } else if (e1 < 0) { + e1 = -e1; + if ((i = e1 & 15)) dval(&rv) /= kDtoaTens[i]; + if (e1 >>= 4) { + if (e1 >= 1u << n_bigtens) goto undfl; #ifdef Avoid_Underflow - if (e1 & Scale_Bit) - bc.scale = 2*P; - for(j = 0; e1 > 0; j++, e1 >>= 1) - if (e1 & 1) - dval(&rv) *= tinytens[j]; - if (bc.scale && (j = 2*P + 1 - ((word0(&rv) & Exp_mask) - >> Exp_shift)) > 0) { - /* scaled rv is denormal; clear j low bits */ - if (j >= 32) { - if (j > 54) - goto undfl; - word1(&rv) = 0; - if (j >= 53) - word0(&rv) = (P+2)*Exp_msk1; - else - word0(&rv) &= 0xffffffff << (j-32); - } - else - word1(&rv) &= 0xffffffff << j; - } + if (e1 & Scale_Bit) bc.scale = 2 * P; + for (j = 0; e1 > 0; j++, e1 >>= 1) + if (e1 & 1) dval(&rv) *= kDtoaTinyTens[j]; + if (bc.scale && + (j = 2 * P + 1 - ((word0(&rv) & Exp_mask) >> Exp_shift)) > 0) { + /* scaled rv is denormal; clear j low bits */ + if (j >= 32) { + if (j > 54) goto undfl; + word1(&rv) = 0; + if (j >= 53) + word0(&rv) = (P + 2) * Exp_msk1; + else + word0(&rv) &= 0xffffffff << (j - 32); + } else + word1(&rv) &= 0xffffffff << j; + } #else - for(j = 0; e1 > 1; j++, e1 >>= 1) - if (e1 & 1) - dval(&rv) *= tinytens[j]; - /* The last multiplication could underflow. */ - dval(&rv0) = dval(&rv); - dval(&rv) *= tinytens[j]; - if (!dval(&rv)) { - dval(&rv) = 2.*dval(&rv0); - dval(&rv) *= tinytens[j]; + for (j = 0; e1 > 1; j++, e1 >>= 1) + if (e1 & 1) dval(&rv) *= kDtoaTinyTens[j]; + /* The last multiplication could underflow. */ + dval(&rv0) = dval(&rv); + dval(&rv) *= kDtoaTinyTens[j]; + if (!dval(&rv)) { + dval(&rv) = 2. * dval(&rv0); + dval(&rv) *= kDtoaTinyTens[j]; #endif - if (!dval(&rv)) { - undfl: - dval(&rv) = 0.; + if (!dval(&rv)) { + undfl: + dval(&rv) = 0.; #ifdef Honor_FLT_ROUNDS - if (bc.rounding == 2) - word1(&rv) = 1; + if (bc.rounding == 2) word1(&rv) = 1; #endif - goto range_err; - } + goto range_err; + } #ifndef Avoid_Underflow - word0(&rv) = Tiny0; - word1(&rv) = Tiny1; - /* The refinement below will clean - * this approximation up. - */ - } + word0(&rv) = Tiny0; + word1(&rv) = Tiny1; + /* The refinement below will clean + * this approximation up. + */ + } #endif - } - } + } +} - /* Now the hard part -- adjusting rv to the correct value.*/ +/* Now the hard part -- adjusting rv to the correct value.*/ - /* Put digits into bd: true value = bd * 10^e */ +/* Put digits into bd: true value = bd * 10^e */ - bc.nd = nd - nz1; +bc.nd = nd - nz1; #ifndef NO_STRTOD_BIGCOMP - bc.nd0 = nd0; /* Only needed if nd > strtod_diglim, but done here */ - /* to silence an erroneous warning about bc.nd0 */ - /* possibly not being initialized. */ - if (nd > strtod_diglim) { - /* ASSERT(strtod_diglim >= 18); 18 == one more than the */ - /* minimum number of decimal digits to distinguish double values */ - /* in IEEE arithmetic. */ - i = j = 18; - if (i > nd0) - j += bc.dplen; - for(;;) { - if (--j < bc.dp1 && j >= bc.dp0) - j = bc.dp0 - 1; - if (s0[j] != '0') - break; - --i; - } - e += nd - i; - nd = i; - if (nd0 > nd) - nd0 = nd; - if (nd < 9) { /* must recompute y */ - y = 0; - for(i = 0; i < nd0; ++i) - y = 10*y + s0[i] - '0'; - for(j = bc.dp1; i < nd; ++i) - y = 10*y + s0[j++] - '0'; - } - } +bc.nd0 = nd0; /* Only needed if nd > strtod_diglim, but done here */ +/* to silence an erroneous warning about bc.nd0 */ +/* possibly not being initialized. */ +if (nd > strtod_diglim) { + /* ASSERT(strtod_diglim >= 18); 18 == one more than the */ + /* minimum number of decimal digits to distinguish double values */ + /* in IEEE arithmetic. */ + i = j = 18; + if (i > nd0) j += bc.dplen; + for (;;) { + if (--j < bc.dp1 && j >= bc.dp0) j = bc.dp0 - 1; + if (s0[j] != '0') break; + --i; + } + e += nd - i; + nd = i; + if (nd0 > nd) nd0 = nd; + if (nd < 9) { /* must recompute y */ + y = 0; + for (i = 0; i < nd0; ++i) y = 10 * y + s0[i] - '0'; + for (j = bc.dp1; i < nd; ++i) y = 10 * y + s0[j++] - '0'; + } +} #endif - bd0 = s2b(s0, nd0, nd, y, bc.dplen MTb); +bd0 = s2b(s0, nd0, nd, y, bc.dplen MTb); - for(;;) { - bd = Balloc(bd0->k MTb); - Bcopy(bd, bd0); - bb = d2b(&rv, &bbe, &bbbits MTb); /* rv = bb * 2^bbe */ - bs = i2b(1 MTb); +for (;;) { + bd = dtoa_balloc(bd0->k MTb); + Bcopy(bd, bd0); + bb = dtoa_d2b(&rv, &bbe, &bbbits MTb); /* rv = bb * 2^bbe */ + bs = dtoa_i2b(1 MTb); - if (e >= 0) { - bb2 = bb5 = 0; - bd2 = bd5 = e; - } - else { - bb2 = bb5 = -e; - bd2 = bd5 = 0; - } - if (bbe >= 0) - bb2 += bbe; - else - bd2 -= bbe; - bs2 = bb2; + if (e >= 0) { + bb2 = bb5 = 0; + bd2 = bd5 = e; + } else { + bb2 = bb5 = -e; + bd2 = bd5 = 0; + } + if (bbe >= 0) + bb2 += bbe; + else + bd2 -= bbe; + bs2 = bb2; #ifdef Honor_FLT_ROUNDS - if (bc.rounding != 1) - bs2++; + if (bc.rounding != 1) bs2++; #endif #ifdef Avoid_Underflow - Lsb = LSB; - Lsb1 = 0; - j = bbe - bc.scale; - i = j + bbbits - 1; /* logb(rv) */ - j = P + 1 - bbbits; - if (i < Emin) { /* denormal */ - i = Emin - i; - j -= i; - if (i < 32) - Lsb <<= i; - else if (i < 52) - Lsb1 = Lsb << (i-32); - else - Lsb1 = Exp_mask; - } + Lsb = LSB; + Lsb1 = 0; + j = bbe - bc.scale; + i = j + bbbits - 1; /* logb(rv) */ + j = P + 1 - bbbits; + if (i < Emin) { /* denormal */ + i = Emin - i; + j -= i; + if (i < 32) + Lsb <<= i; + else if (i < 52) + Lsb1 = Lsb << (i - 32); + else + Lsb1 = Exp_mask; + } #else /*Avoid_Underflow*/ #ifdef Sudden_Underflow #ifdef IBM - j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3); + j = 1 + 4 * P - 3 - bbbits + ((bbe + bbbits - 1) & 3); #else - j = P + 1 - bbbits; + j = P + 1 - bbbits; #endif -#else /*Sudden_Underflow*/ - j = bbe; - i = j + bbbits - 1; /* logb(rv) */ - if (i < Emin) /* denormal */ - j += P - Emin; - else - j = P + 1 - bbbits; +#else /*Sudden_Underflow*/ + j = bbe; + i = j + bbbits - 1; /* logb(rv) */ + if (i < Emin) /* denormal */ + j += P - Emin; + else + j = P + 1 - bbbits; #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ - bb2 += j; - bd2 += j; + bb2 += j; + bd2 += j; #ifdef Avoid_Underflow - bd2 += bc.scale; + bd2 += bc.scale; #endif - i = bb2 < bd2 ? bb2 : bd2; - if (i > bs2) - i = bs2; - if (i > 0) { - bb2 -= i; - bd2 -= i; - bs2 -= i; - } - if (bb5 > 0) { - bs = pow5mult(bs, bb5 MTb); - bb1 = mult(bs, bb MTb); - Bfree(bb MTb); - bb = bb1; - } - if (bb2 > 0) - bb = lshift(bb, bb2 MTb); - if (bd5 > 0) - bd = pow5mult(bd, bd5 MTb); - if (bd2 > 0) - bd = lshift(bd, bd2 MTb); - if (bs2 > 0) - bs = lshift(bs, bs2 MTb); - delta = diff(bb, bd MTb); - bc.dsign = delta->sign; - delta->sign = 0; - i = cmp(delta, bs); + i = bb2 < bd2 ? bb2 : bd2; + if (i > bs2) i = bs2; + if (i > 0) { + bb2 -= i; + bd2 -= i; + bs2 -= i; + } + if (bb5 > 0) { + bs = dtoa_pow5mult(bs, bb5 MTb); + bb1 = dtoa_mult(bs, bb MTb); + dtoa_bfree(bb MTb); + bb = bb1; + } + if (bb2 > 0) bb = dtoa_lshift(bb, bb2 MTb); + if (bd5 > 0) bd = dtoa_pow5mult(bd, bd5 MTb); + if (bd2 > 0) bd = dtoa_lshift(bd, bd2 MTb); + if (bs2 > 0) bs = dtoa_lshift(bs, bs2 MTb); + delta = dtoa_diff(bb, bd MTb); + bc.dsign = delta->sign; + delta->sign = 0; + i = dtoa_cmp(delta, bs); #ifndef NO_STRTOD_BIGCOMP /*{*/ - if (bc.nd > nd && i <= 0) { - if (bc.dsign) { - /* Must use bigcomp(). */ - req_bigcomp = 1; - break; - } + if (bc.nd > nd && i <= 0) { + if (bc.dsign) { + /* Must use dtoa_bigcomp(). */ + req_dtoa_bigcomp = 1; + break; + } #ifdef Honor_FLT_ROUNDS - if (bc.rounding != 1) { - if (i < 0) { - req_bigcomp = 1; - break; - } - } - else + if (bc.rounding != 1) { + if (i < 0) { + req_dtoa_bigcomp = 1; + break; + } + } else #endif - i = -1; /* Discarded digits make delta smaller. */ - } -#endif /*}*/ + i = -1; /* Discarded digits make delta smaller. */ + } +#endif /*}*/ #ifdef Honor_FLT_ROUNDS /*{*/ - if (bc.rounding != 1) { - if (i < 0) { - /* Error is less than an ulp */ - if (!delta->x[0] && delta->wds <= 1) { - /* exact */ + if (bc.rounding != 1) { + if (i < 0) { + /* Error is less than an ulp */ + if (!delta->x[0] && delta->wds <= 1) { + /* exact */ #ifdef SET_INEXACT - bc.inexact = 0; + bc.inexact = 0; #endif - break; - } - if (bc.rounding) { - if (bc.dsign) { - adj.d = 1.; - goto apply_adj; - } - } - else if (!bc.dsign) { - adj.d = -1.; - if (!word1(&rv) - && !(word0(&rv) & Frac_mask)) { - y = word0(&rv) & Exp_mask; + break; + } + if (bc.rounding) { + if (bc.dsign) { + adj.d = 1.; + goto apply_adj; + } + } else if (!bc.dsign) { + adj.d = -1.; + if (!word1(&rv) && !(word0(&rv) & Frac_mask)) { + y = word0(&rv) & Exp_mask; #ifdef Avoid_Underflow - if (!bc.scale || y > 2*P*Exp_msk1) + if (!bc.scale || y > 2 * P * Exp_msk1) #else - if (y) + if (y) #endif - { - delta = lshift(delta,Log2P MTb); - if (cmp(delta, bs) <= 0) - adj.d = -0.5; - } - } - apply_adj: + { + delta = dtoa_lshift(delta, Log2P MTb); + if (dtoa_cmp(delta, bs) <= 0) adj.d = -0.5; + } + } + apply_adj: #ifdef Avoid_Underflow /*{*/ - if (bc.scale && (y = word0(&rv) & Exp_mask) - <= 2*P*Exp_msk1) - word0(&adj) += (2*P+1)*Exp_msk1 - y; + if (bc.scale && (y = word0(&rv) & Exp_mask) <= 2 * P * Exp_msk1) + word0(&adj) += (2 * P + 1) * Exp_msk1 - y; #else #ifdef Sudden_Underflow - if ((word0(&rv) & Exp_mask) <= - P*Exp_msk1) { - word0(&rv) += P*Exp_msk1; - dval(&rv) += adj.d*ulp(dval(&rv)); - word0(&rv) -= P*Exp_msk1; - } - else + if ((word0(&rv) & Exp_mask) <= P * Exp_msk1) { + word0(&rv) += P * Exp_msk1; + dval(&rv) += adj.d * ulp(dval(&rv)); + word0(&rv) -= P * Exp_msk1; + } else #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow}*/ - dval(&rv) += adj.d*ulp(&rv); - } - break; - } - adj.d = ratio(delta, bs); - if (adj.d < 1.) - adj.d = 1.; - if (adj.d <= 0x7ffffffe) { - /* adj = rounding ? ceil(adj) : floor(adj); */ - y = adj.d; - if (y != adj.d) { - if (!((bc.rounding>>1) ^ bc.dsign)) - y++; - adj.d = y; - } - } + dval(&rv) += adj.d * ulp(&rv); + } + break; + } + adj.d = dtoaratio(delta, bs); + if (adj.d < 1.) adj.d = 1.; + if (adj.d <= 0x7ffffffe) { + /* adj = rounding ? ceil(adj) : floor(adj); */ + y = adj.d; + if (y != adj.d) { + if (!((bc.rounding >> 1) ^ bc.dsign)) y++; + adj.d = y; + } + } #ifdef Avoid_Underflow /*{*/ - if (bc.scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1) - word0(&adj) += (2*P+1)*Exp_msk1 - y; + if (bc.scale && (y = word0(&rv) & Exp_mask) <= 2 * P * Exp_msk1) + word0(&adj) += (2 * P + 1) * Exp_msk1 - y; #else #ifdef Sudden_Underflow - if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) { - word0(&rv) += P*Exp_msk1; - adj.d *= ulp(dval(&rv)); - if (bc.dsign) - dval(&rv) += adj.d; - else - dval(&rv) -= adj.d; - word0(&rv) -= P*Exp_msk1; - goto cont; - } + if ((word0(&rv) & Exp_mask) <= P * Exp_msk1) { + word0(&rv) += P * Exp_msk1; + adj.d *= ulp(dval(&rv)); + if (bc.dsign) + dval(&rv) += adj.d; + else + dval(&rv) -= adj.d; + word0(&rv) -= P * Exp_msk1; + goto cont; + } #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow}*/ - adj.d *= ulp(&rv); - if (bc.dsign) { - if (word0(&rv) == Big0 && word1(&rv) == Big1) - goto ovfl; - dval(&rv) += adj.d; - } - else - dval(&rv) -= adj.d; - goto cont; - } + adj.d *= ulp(&rv); + if (bc.dsign) { + if (word0(&rv) == Big0 && word1(&rv) == Big1) goto ovfl; + dval(&rv) += adj.d; + } else + dval(&rv) -= adj.d; + goto cont; + } #endif /*}Honor_FLT_ROUNDS*/ - if (i < 0) { - /* Error is less than half an ulp -- check for - * special case of mantissa a power of two. - */ - if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask + if (i < 0) { + /* Error is less than half an ulp -- check for + * special case of mantissa a power of two. + */ + if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask #ifdef IEEE_Arith /*{*/ #ifdef Avoid_Underflow - || (word0(&rv) & Exp_mask) <= (2*P+1)*Exp_msk1 + || (word0(&rv) & Exp_mask) <= (2 * P + 1) * Exp_msk1 #else - || (word0(&rv) & Exp_mask) <= Exp_msk1 + || (word0(&rv) & Exp_mask) <= Exp_msk1 #endif #endif /*}*/ - ) { + ) { #ifdef SET_INEXACT - if (!delta->x[0] && delta->wds <= 1) - bc.inexact = 0; + if (!delta->x[0] && delta->wds <= 1) bc.inexact = 0; #endif - break; - } - if (!delta->x[0] && delta->wds <= 1) { - /* exact result */ + break; + } + if (!delta->x[0] && delta->wds <= 1) { + /* exact result */ #ifdef SET_INEXACT - bc.inexact = 0; + bc.inexact = 0; #endif - break; - } - delta = lshift(delta,Log2P MTb); - if (cmp(delta, bs) > 0) - goto drop_down; - break; - } - if (i == 0) { - /* exactly half-way between */ - if (bc.dsign) { - if ((word0(&rv) & Bndry_mask1) == Bndry_mask1 - && word1(&rv) == ( + break; + } + delta = dtoa_lshift(delta, Log2P MTb); + if (dtoa_cmp(delta, bs) > 0) goto drop_down; + break; + } + if (i == 0) { + /* exactly half-way between */ + if (bc.dsign) { + if ((word0(&rv) & Bndry_mask1) == Bndry_mask1 && + word1(&rv) == + ( #ifdef Avoid_Underflow - (bc.scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1) - ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) : + (bc.scale && (y = word0(&rv) & Exp_mask) <= 2 * P * Exp_msk1) + ? (0xffffffff & + (0xffffffff << (2 * P + 1 - (y >> Exp_shift)))) + : #endif - 0xffffffff)) { - /*boundary case -- increment exponent*/ - if (word0(&rv) == Big0 && word1(&rv) == Big1) - goto ovfl; - word0(&rv) = (word0(&rv) & Exp_mask) - + Exp_msk1 + 0xffffffff)) { + /*boundary case -- increment exponent*/ + if (word0(&rv) == Big0 && word1(&rv) == Big1) goto ovfl; + word0(&rv) = (word0(&rv) & Exp_mask) + Exp_msk1 #ifdef IBM - | Exp_msk1 >> 4 + | Exp_msk1 >> 4 #endif - ; - word1(&rv) = 0; + ; + word1(&rv) = 0; #ifdef Avoid_Underflow - bc.dsign = 0; + bc.dsign = 0; #endif - break; - } - } - else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) { - drop_down: - /* boundary case -- decrement exponent */ + break; + } + } else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) { + drop_down: + /* boundary case -- decrement exponent */ #ifdef Sudden_Underflow /*{{*/ - L = word0(&rv) & Exp_mask; + L = word0(&rv) & Exp_mask; #ifdef IBM - if (L < Exp_msk1) + if (L < Exp_msk1) #else #ifdef Avoid_Underflow - if (L <= (bc.scale ? (2*P+1)*Exp_msk1 : Exp_msk1)) + if (L <= (bc.scale ? (2 * P + 1) * Exp_msk1 : Exp_msk1)) #else - if (L <= Exp_msk1) + if (L <= Exp_msk1) #endif /*Avoid_Underflow*/ #endif /*IBM*/ - { - if (bc.nd >nd) { - bc.uflchk = 1; - break; - } - goto undfl; - } - L -= Exp_msk1; + { + if (bc.nd > nd) { + bc.uflchk = 1; + break; + } + goto undfl; + } + L -= Exp_msk1; #else /*Sudden_Underflow}{*/ #ifdef Avoid_Underflow - if (bc.scale) { - L = word0(&rv) & Exp_mask; - if (L <= (2*P+1)*Exp_msk1) { - if (L > (P+2)*Exp_msk1) - /* round even ==> */ - /* accept rv */ - break; - /* rv = smallest denormal */ - if (bc.nd >nd) { - bc.uflchk = 1; - break; - } - goto undfl; - } - } + if (bc.scale) { + L = word0(&rv) & Exp_mask; + if (L <= (2 * P + 1) * Exp_msk1) { + if (L > (P + 2) * Exp_msk1) /* round even ==> */ + /* accept rv */ + break; + /* rv = smallest denormal */ + if (bc.nd > nd) { + bc.uflchk = 1; + break; + } + goto undfl; + } + } #endif /*Avoid_Underflow*/ - L = (word0(&rv) & Exp_mask) - Exp_msk1; + L = (word0(&rv) & Exp_mask) - Exp_msk1; #endif /*Sudden_Underflow}}*/ - word0(&rv) = L | Bndry_mask1; - word1(&rv) = 0xffffffff; + word0(&rv) = L | Bndry_mask1; + word1(&rv) = 0xffffffff; #ifdef IBM - goto cont; + goto cont; #else #ifndef NO_STRTOD_BIGCOMP - if (bc.nd > nd) - goto cont; + if (bc.nd > nd) goto cont; #endif - break; + break; #endif - } + } #ifndef ROUND_BIASED #ifdef Avoid_Underflow - if (Lsb1) { - if (!(word0(&rv) & Lsb1)) - break; - } - else if (!(word1(&rv) & Lsb)) - break; + if (Lsb1) { + if (!(word0(&rv) & Lsb1)) break; + } else if (!(word1(&rv) & Lsb)) + break; #else - if (!(word1(&rv) & LSB)) - break; + if (!(word1(&rv) & LSB)) break; #endif #endif - if (bc.dsign) + if (bc.dsign) #ifdef Avoid_Underflow - dval(&rv) += sulp(&rv, &bc); + dval(&rv) += dtoa_sulp(&rv, &bc); #else - dval(&rv) += ulp(&rv); + dval(&rv) += ulp(&rv); #endif #ifndef ROUND_BIASED - else { + else { #ifdef Avoid_Underflow - dval(&rv) -= sulp(&rv, &bc); + dval(&rv) -= dtoa_sulp(&rv, &bc); #else - dval(&rv) -= ulp(&rv); + dval(&rv) -= ulp(&rv); #endif #ifndef Sudden_Underflow - if (!dval(&rv)) { - if (bc.nd >nd) { - bc.uflchk = 1; - break; - } - goto undfl; - } + if (!dval(&rv)) { + if (bc.nd > nd) { + bc.uflchk = 1; + break; + } + goto undfl; + } #endif - } + } #ifdef Avoid_Underflow - bc.dsign = 1 - bc.dsign; + bc.dsign = 1 - bc.dsign; #endif #endif - break; - } - if ((aadj = ratio(delta, bs)) <= 2.) { - if (bc.dsign) - aadj = aadj1 = 1.; - else if (word1(&rv) || word0(&rv) & Bndry_mask) { + break; + } + if ((aadj = dtoaratio(delta, bs)) <= 2.) { + if (bc.dsign) + aadj = aadj1 = 1.; + else if (word1(&rv) || word0(&rv) & Bndry_mask) { #ifndef Sudden_Underflow - if (word1(&rv) == Tiny1 && !word0(&rv)) { - if (bc.nd >nd) { - bc.uflchk = 1; - break; - } - goto undfl; - } + if (word1(&rv) == Tiny1 && !word0(&rv)) { + if (bc.nd > nd) { + bc.uflchk = 1; + break; + } + goto undfl; + } #endif - aadj = 1.; - aadj1 = -1.; - } - else { - /* special case -- power of FLT_RADIX to be */ - /* rounded down... */ + aadj = 1.; + aadj1 = -1.; + } else { + /* special case -- power of FLT_RADIX to be */ + /* rounded down... */ - if (aadj < 2./FLT_RADIX) - aadj = 1./FLT_RADIX; - else - aadj *= 0.5; - aadj1 = -aadj; - } - } - else { - aadj *= 0.5; - aadj1 = bc.dsign ? aadj : -aadj; + if (aadj < 2. / FLT_RADIX) + aadj = 1. / FLT_RADIX; + else + aadj *= 0.5; + aadj1 = -aadj; + } + } else { + aadj *= 0.5; + aadj1 = bc.dsign ? aadj : -aadj; #ifdef Check_FLT_ROUNDS - switch(bc.rounding) { - case 2: /* towards +infinity */ - aadj1 -= 0.5; - break; - case 0: /* towards 0 */ - case 3: /* towards -infinity */ - aadj1 += 0.5; - } + switch (bc.rounding) { + case 2: /* towards +infinity */ + aadj1 -= 0.5; + break; + case 0: /* towards 0 */ + case 3: /* towards -infinity */ + aadj1 += 0.5; + } #else - if (Flt_Rounds == 0) - aadj1 += 0.5; + if (Flt_Rounds == 0) aadj1 += 0.5; #endif /*Check_FLT_ROUNDS*/ - } - y = word0(&rv) & Exp_mask; + } + y = word0(&rv) & Exp_mask; - /* Check for overflow */ + /* Check for overflow */ - if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { - dval(&rv0) = dval(&rv); - word0(&rv) -= P*Exp_msk1; - adj.d = aadj1 * ulp(&rv); - dval(&rv) += adj.d; - if ((word0(&rv) & Exp_mask) >= - Exp_msk1*(DBL_MAX_EXP+Bias-P)) { - if (word0(&rv0) == Big0 && word1(&rv0) == Big1) - goto ovfl; - word0(&rv) = Big0; - word1(&rv) = Big1; - goto cont; - } - else - word0(&rv) += P*Exp_msk1; - } - else { + if (y == Exp_msk1 * (DBL_MAX_EXP + Bias - 1)) { + dval(&rv0) = dval(&rv); + word0(&rv) -= P * Exp_msk1; + adj.d = aadj1 * ulp(&rv); + dval(&rv) += adj.d; + if ((word0(&rv) & Exp_mask) >= Exp_msk1 * (DBL_MAX_EXP + Bias - P)) { + if (word0(&rv0) == Big0 && word1(&rv0) == Big1) goto ovfl; + word0(&rv) = Big0; + word1(&rv) = Big1; + goto cont; + } else + word0(&rv) += P * Exp_msk1; + } else { #ifdef Avoid_Underflow - if (bc.scale && y <= 2*P*Exp_msk1) { - if (aadj <= 0x7fffffff) { - if ((z = aadj) <= 0) - z = 1; - aadj = z; - aadj1 = bc.dsign ? aadj : -aadj; - } - dval(&aadj2) = aadj1; - word0(&aadj2) += (2*P+1)*Exp_msk1 - y; - aadj1 = dval(&aadj2); - adj.d = aadj1 * ulp(&rv); - dval(&rv) += adj.d; - if (rv.d == 0.) + if (bc.scale && y <= 2 * P * Exp_msk1) { + if (aadj <= 0x7fffffff) { + if ((z = aadj) <= 0) z = 1; + aadj = z; + aadj1 = bc.dsign ? aadj : -aadj; + } + dval(&aadj2) = aadj1; + word0(&aadj2) += (2 * P + 1) * Exp_msk1 - y; + aadj1 = dval(&aadj2); + adj.d = aadj1 * ulp(&rv); + dval(&rv) += adj.d; + if (rv.d == 0.) #ifdef NO_STRTOD_BIGCOMP - goto undfl; + goto undfl; #else - { - req_bigcomp = 1; - break; - } + { + req_dtoa_bigcomp = 1; + break; + } #endif - } - else { - adj.d = aadj1 * ulp(&rv); - dval(&rv) += adj.d; - } + } else { + adj.d = aadj1 * ulp(&rv); + dval(&rv) += adj.d; + } #else #ifdef Sudden_Underflow - if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) { - dval(&rv0) = dval(&rv); - word0(&rv) += P*Exp_msk1; - adj.d = aadj1 * ulp(&rv); - dval(&rv) += adj.d; + if ((word0(&rv) & Exp_mask) <= P * Exp_msk1) { + dval(&rv0) = dval(&rv); + word0(&rv) += P * Exp_msk1; + adj.d = aadj1 * ulp(&rv); + dval(&rv) += adj.d; #ifdef IBM - if ((word0(&rv) & Exp_mask) < P*Exp_msk1) + if ((word0(&rv) & Exp_mask) < P * Exp_msk1) #else - if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) + if ((word0(&rv) & Exp_mask) <= P * Exp_msk1) #endif - { - if (word0(&rv0) == Tiny0 - && word1(&rv0) == Tiny1) { - if (bc.nd >nd) { - bc.uflchk = 1; - break; - } - goto undfl; - } - word0(&rv) = Tiny0; - word1(&rv) = Tiny1; - goto cont; - } - else - word0(&rv) -= P*Exp_msk1; - } - else { - adj.d = aadj1 * ulp(&rv); - dval(&rv) += adj.d; - } -#else /*Sudden_Underflow*/ - /* Compute adj so that the IEEE rounding rules will - * correctly round rv + adj in some half-way cases. - * If rv * ulp(rv) is denormalized (i.e., - * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid - * trouble from bits lost to denormalization; - * example: 1.2e-307 . - */ - if (y <= (P-1)*Exp_msk1 && aadj > 1.) { - aadj1 = (double)(int)(aadj + 0.5); - if (!bc.dsign) - aadj1 = -aadj1; - } - adj.d = aadj1 * ulp(&rv); - dval(&rv) += adj.d; + { + if (word0(&rv0) == Tiny0 && word1(&rv0) == Tiny1) { + if (bc.nd > nd) { + bc.uflchk = 1; + break; + } + goto undfl; + } + word0(&rv) = Tiny0; + word1(&rv) = Tiny1; + goto cont; + } else + word0(&rv) -= P * Exp_msk1; + } else { + adj.d = aadj1 * ulp(&rv); + dval(&rv) += adj.d; + } +#else /*Sudden_Underflow*/ + /* Compute adj so that the IEEE rounding rules will + * correctly round rv + adj in some half-way cases. + * If rv * ulp(rv) is denormalized (i.e., + * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid + * trouble from bits lost to denormalization; + * example: 1.2e-307 . + */ + if (y <= (P - 1) * Exp_msk1 && aadj > 1.) { + aadj1 = (double)(int)(aadj + 0.5); + if (!bc.dsign) aadj1 = -aadj1; + } + adj.d = aadj1 * ulp(&rv); + dval(&rv) += adj.d; #endif /*Sudden_Underflow*/ #endif /*Avoid_Underflow*/ - } - z = word0(&rv) & Exp_mask; + } + z = word0(&rv) & Exp_mask; #ifndef SET_INEXACT - if (bc.nd == nd) { + if (bc.nd == nd) { #ifdef Avoid_Underflow - if (!bc.scale) + if (!bc.scale) #endif - if (y == z) { - /* Can we stop now? */ - L = (Long)aadj; - aadj -= L; - /* The tolerances below are conservative. */ - if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask) { - if (aadj < .4999999 || aadj > .5000001) - break; - } - else if (aadj < .4999999/FLT_RADIX) - break; - } - } + if (y == z) { + /* Can we stop now? */ + L = (Long)aadj; + aadj -= L; + /* The tolerances below are conservative. */ + if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask) { + if (aadj < .4999999 || aadj > .5000001) break; + } else if (aadj < .4999999 / FLT_RADIX) + break; + } + } #endif - cont: - Bfree(bb MTb); - Bfree(bd MTb); - Bfree(bs MTb); - Bfree(delta MTb); - } - Bfree(bb MTb); - Bfree(bd MTb); - Bfree(bs MTb); - Bfree(bd0 MTb); - Bfree(delta MTb); +cont: + dtoa_bfree(bb MTb); + dtoa_bfree(bd MTb); + dtoa_bfree(bs MTb); + dtoa_bfree(delta MTb); +} +dtoa_bfree(bb MTb); +dtoa_bfree(bd MTb); +dtoa_bfree(bs MTb); +dtoa_bfree(bd0 MTb); +dtoa_bfree(delta MTb); #ifndef NO_STRTOD_BIGCOMP - if (req_bigcomp) { - bd0 = 0; - bc.e0 += nz1; - bigcomp(&rv, s0, &bc MTb); - y = word0(&rv) & Exp_mask; - if (y == Exp_mask) - goto ovfl; - if (y == 0 && rv.d == 0.) - goto undfl; - } +if (req_dtoa_bigcomp) { + bd0 = 0; + bc.e0 += nz1; + dtoa_bigcomp(&rv, s0, &bc MTb); + y = word0(&rv) & Exp_mask; + if (y == Exp_mask) goto ovfl; + if (y == 0 && rv.d == 0.) goto undfl; +} #endif #ifdef Avoid_Underflow - if (bc.scale) { - word0(&rv0) = Exp_1 - 2*P*Exp_msk1; - word1(&rv0) = 0; - dval(&rv) *= dval(&rv0); +if (bc.scale) { + word0(&rv0) = Exp_1 - 2 * P * Exp_msk1; + word1(&rv0) = 0; + dval(&rv) *= dval(&rv0); #ifndef NO_ERRNO - /* try to avoid the bug of testing an 8087 register value */ + /* try to avoid the bug of testing an 8087 register value */ #ifdef IEEE_Arith - if (!(word0(&rv) & Exp_mask)) + if (!(word0(&rv) & Exp_mask)) #else - if (word0(&rv) == 0 && word1(&rv) == 0) + if (word0(&rv) == 0 && word1(&rv) == 0) #endif - Set_errno(erange); + Set_errno(erange); #endif - } +} #endif /* Avoid_Underflow */ - ret: +ret : #ifdef SET_INEXACT - if (bc.inexact) { - if (!(word0(&rv) & Exp_mask)) { - /* set underflow and inexact bits */ - dval(&rv0) = 1e-300; - dval(&rv0) *= dval(&rv0); - } - else if (!oldinexact) { - word0(&rv0) = Exp_1 + (70 << Exp_shift); - word1(&rv0) = 0; - dval(&rv0) += 1.; - } - } - else if (!oldinexact) - clear_inexact(); + if (bc.inexact) { + if (!(word0(&rv) & Exp_mask)) { + /* set underflow and inexact bits */ + dval(&rv0) = 1e-300; + dval(&rv0) *= dval(&rv0); + } else if (!oldinexact) { + word0(&rv0) = Exp_1 + (70 << Exp_shift); + word1(&rv0) = 0; + dval(&rv0) += 1.; + } +} +else if (!oldinexact) clear_inexact(); #endif - if (se) - *se = (char *)s; - if (sign) { - return -dval(&rv); - } else { - return dval(&rv); - } - } +if (se) *se = (char *)s; +if (sign) { + return -dval(&rv); +} else { + return dval(&rv); +} +} #ifndef MULTIPLE_THREADS - static char *dtoa_result; +static char *dtoa_result; #endif - static char * -rv_alloc(int i MTd) -{ - int j, k, *r; +static char *dtoa_rv_alloc(int i MTd) { + int j, k, *r; - j = sizeof(ULong); - for(k = 0; - sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i; - j <<= 1) - k++; - r = (int*)Balloc(k MTa); - *r = k; - return + j = sizeof(ULong); + for (k = 0; sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i; j <<= 1) + k++; + r = (int *)dtoa_balloc(k MTa); + *r = k; + return #ifndef MULTIPLE_THREADS - dtoa_result = + dtoa_result = #endif - (char *)(r+1); - } + (char *)(r + 1); +} - static char * -nrv_alloc(const char *s, char *s0, size_t s0len, char **rve, int n MTd) -{ - char *rv, *t; +static char *dtoa_nrv_alloc(const char *s, char *s0, size_t s0len, char **rve, + int n MTd) { + char *rv, *t; - if (!s0) - s0 = rv_alloc(n MTa); - else if (s0len <= n) { - rv = 0; - t = rv + n; - goto rve_chk; - } - t = rv = s0; - while((*t = *s++)) - ++t; - rve_chk: - if (rve) - *rve = t; - return rv; - } + if (!s0) + s0 = dtoa_rv_alloc(n MTa); + else if (s0len <= n) { + rv = 0; + t = rv + n; + goto rve_chk; + } + t = rv = s0; + while ((*t = *s++)) ++t; +rve_chk: + if (rve) *rve = t; + return rv; +} /* freedtoa(s) must be used to free values s returned by dtoa * when MULTIPLE_THREADS is #defined. It should be used in all cases, @@ -4928,20 +4632,17 @@ nrv_alloc(const char *s, char *s0, size_t s0len, char **rve, int n MTd) * when MULTIPLE_THREADS is not defined. */ - void -freedtoa(char *s) -{ +void freedtoa(char *s) { #ifdef MULTIPLE_THREADS - ThInfo *TI = 0; + ThInfo *TI = 0; #endif - Bigint *b = (Bigint *)((int *)s - 1); - b->maxwds = 1 << (b->k = *(int*)b); - Bfree(b MTb); + Bigint *b = (Bigint *)((int *)s - 1); + b->maxwds = 1 << (b->k = *(int *)b); + dtoa_bfree(b MTb); #ifndef MULTIPLE_THREADS - if (s == dtoa_result) - dtoa_result = 0; + if (s == dtoa_result) dtoa_result = 0; #endif - } +} /* dtoa for IEEE arithmetic (dmg): convert double to ASCII string. * @@ -4977,1255 +4678,1168 @@ freedtoa(char *s) * calculation. */ - char * -dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char *buf, size_t blen) -{ - /* Arguments ndigits, decpt, sign are similar to those - of ecvt and fcvt; trailing zeros are suppressed from - the returned string. If not null, *rve is set to point - to the end of the return value. If d is +-Infinity or NaN, - then *decpt is set to 9999. +char *dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, + char **rve, char *buf, size_t blen) { + /* Arguments ndigits, decpt, sign are similar to those + of ecvt and fcvt; trailing zeros are suppressed from + the returned string. If not null, *rve is set to point + to the end of the return value. If d is +-Infinity or NaN, + then *decpt is set to 9999. - mode: - 0 ==> shortest string that yields d when read in - and rounded to nearest. - 1 ==> like 0, but with Steele & White stopping rule; - e.g. with IEEE P754 arithmetic , mode 0 gives - 1e23 whereas mode 1 gives 9.999999999999999e22. - 2 ==> max(1,ndigits) significant digits. This gives a - return value similar to that of ecvt, except - that trailing zeros are suppressed. - 3 ==> through ndigits past the decimal point. This - gives a return value similar to that from fcvt, - except that trailing zeros are suppressed, and - ndigits can be negative. - 4,5 ==> similar to 2 and 3, respectively, but (in - round-nearest mode) with the tests of mode 0 to - possibly return a shorter string that rounds to d. - With IEEE arithmetic and compilation with - -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same - as modes 2 and 3 when FLT_ROUNDS != 1. - 6-9 ==> Debugging modes similar to mode - 4: don't try - fast floating-point estimate (if applicable). + mode: + 0 ==> shortest string that yields d when read in + and rounded to nearest. + 1 ==> like 0, but with Steele & White stopping rule; + e.g. with IEEE P754 arithmetic , mode 0 gives + 1e23 whereas mode 1 gives 9.999999999999999e22. + 2 ==> max(1,ndigits) significant digits. This gives a + return value similar to that of ecvt, except + that trailing zeros are suppressed. + 3 ==> through ndigits past the decimal point. This + gives a return value similar to that from fcvt, + except that trailing zeros are suppressed, and + ndigits can be negative. + 4,5 ==> similar to 2 and 3, respectively, but (in + round-nearest mode) with the tests of mode 0 to + possibly return a shorter string that rounds to d. + With IEEE arithmetic and compilation with + -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same + as modes 2 and 3 when FLT_ROUNDS != 1. + 6-9 ==> Debugging modes similar to mode - 4: don't try + fast floating-point estimate (if applicable). - Values of mode other than 0-9 are treated as mode 0. + Values of mode other than 0-9 are treated as mode 0. - When not NULL, buf is an output buffer of length blen, which must - be large enough to accommodate suppressed trailing zeros and a trailing - null byte. If blen is too small, rv = NULL is returned, in which case - if rve is not NULL, a subsequent call with blen >= (*rve - rv) + 1 - should succeed in returning buf. + When not NULL, buf is an output buffer of length blen, which must + be large enough to accommodate suppressed trailing zeros and a trailing + null byte. If blen is too small, rv = NULL is returned, in which case + if rve is not NULL, a subsequent call with blen >= (*rve - rv) + 1 + should succeed in returning buf. - When buf is NULL, sufficient space is allocated for the return value, - which, when done using, the caller should pass to freedtoa(). + When buf is NULL, sufficient space is allocated for the return value, + which, when done using, the caller should pass to freedtoa(). - USE_BF is automatically defined when neither NO_LONG_LONG nor NO_BF96 - is defined. - */ + USE_BF is automatically defined when neither NO_LONG_LONG nor NO_BF96 + is defined. + */ #ifdef MULTIPLE_THREADS - ThInfo *TI = 0; + ThInfo *TI = 0; #endif - int bbits, b2, b5, be, dig, i, ilim, ilim1, - j, j1, k, leftright, m2, m5, s2, s5, spec_case; + int bbits, b2, b5, be, dig, i, ilim, ilim1, j, j1, k, leftright, m2, m5, s2, + s5, spec_case; #if !defined(Sudden_Underflow) || defined(USE_BF96) - int denorm; + int denorm; #endif - Bigint *b, *b1, *delta, *mlo, *mhi, *S; - U u; - char *s; + Bigint *b, *b1, *delta, *mlo, *mhi, *S; + U u; + char *s; #ifdef SET_INEXACT - int inexact, oldinexact; + int inexact, oldinexact; #endif #ifdef USE_BF96 /*{{*/ - BF96 *p10; - ULLong dbhi, dbits, dblo, den, hb, rb, rblo, res, res0, res3, reslo, sres, - sulp, tv0, tv1, tv2, tv3, ulp, ulplo, ulpmask, ures, ureslo, zb; - int eulp, k1, n2, ulpadj, ulpshift; + BF96 *p10; + ULLong dbhi, dbits, dblo, den, hb, rb, rblo, res, res0, res3, reslo, sres, + dtoa_sulp, tv0, tv1, tv2, tv3, ulp, ulplo, ulpmask, ures, ureslo, zb; + int eulp, k1, n2, ulpadj, ulpshift; #else /*}{*/ #ifndef Sudden_Underflow - ULong x; + ULong x; #endif - Long L; - U d2, eps; - double ds; - int ieps, ilim0, k0, k_check, try_quick; + Long L; + U d2, eps; + double ds; + int ieps, ilim0, k0, k_check, try_quick; #ifndef No_leftright #ifdef IEEE_Arith - U eps1; + U eps1; #endif #endif -#endif /*}}*/ +#endif /*}}*/ #ifdef Honor_FLT_ROUNDS /*{*/ - int Rounding; + int Rounding; #ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */ - Rounding = Flt_Rounds; -#else /*}{*/ - Rounding = 1; - switch(fegetround()) { - case FE_TOWARDZERO: Rounding = 0; break; - case FE_UPWARD: Rounding = 2; break; - case FE_DOWNWARD: Rounding = 3; - } + Rounding = Flt_Rounds; +#else /*}{*/ + Rounding = 1; + switch (fegetround()) { + case FE_TOWARDZERO: + Rounding = 0; + break; + case FE_UPWARD: + Rounding = 2; + break; + case FE_DOWNWARD: + Rounding = 3; + } #endif /*}}*/ #endif /*}*/ - u.d = dd; - if (word0(&u) & Sign_bit) { - /* set sign for everything, including 0's and NaNs */ - *sign = 1; - word0(&u) &= ~Sign_bit; /* clear sign bit */ - } - else - *sign = 0; + u.d = dd; + if (word0(&u) & Sign_bit) { + /* set sign for everything, including 0's and NaNs */ + *sign = 1; + word0(&u) &= ~Sign_bit; /* clear sign bit */ + } else + *sign = 0; #if defined(IEEE_Arith) + defined(VAX) #ifdef IEEE_Arith - if ((word0(&u) & Exp_mask) == Exp_mask) + if ((word0(&u) & Exp_mask) == Exp_mask) #else - if (word0(&u) == 0x8000) + if (word0(&u) == 0x8000) #endif - { - /* Infinity or NaN */ - *decpt = 9999; + { + /* Infinity or NaN */ + *decpt = 9999; #ifdef IEEE_Arith - if (!word1(&u) && !(word0(&u) & 0xfffff)) - return nrv_alloc("INFINITY", buf, blen, rve, 8 MTb); + if (!word1(&u) && !(word0(&u) & 0xfffff)) + return dtoa_nrv_alloc("inf", buf, blen, rve, 8 MTb); #endif - return nrv_alloc("NAN", buf, blen, rve, 3 MTb); - } + return dtoa_nrv_alloc("nan", buf, blen, rve, 3 MTb); + } #endif #ifdef IBM - dval(&u) += 0; /* normalize */ + dval(&u) += 0; /* normalize */ #endif - if (!dval(&u)) { - *decpt = 1; - return nrv_alloc("0", buf, blen, rve, 1 MTb); - } + if (!dval(&u)) { + *decpt = 1; + return dtoa_nrv_alloc("0", buf, blen, rve, 1 MTb); + } #ifdef SET_INEXACT #ifndef USE_BF96 - try_quick = + try_quick = #endif - oldinexact = get_inexact(); - inexact = 1; + oldinexact = get_inexact(); + inexact = 1; #endif #ifdef Honor_FLT_ROUNDS - if (Rounding >= 2) { - if (*sign) - Rounding = Rounding == 2 ? 0 : 2; - else - if (Rounding != 2) - Rounding = 0; - } + if (Rounding >= 2) { + if (*sign) + Rounding = Rounding == 2 ? 0 : 2; + else if (Rounding != 2) + Rounding = 0; + } #endif -#ifdef USE_BF96 /*{{*/ - dbits = (u.LL & 0xfffffffffffffull) << 11; /* fraction bits */ - if ((be = u.LL >> 52)) /* biased exponent; nonzero ==> normal */ { - dbits |= 0x8000000000000000ull; - denorm = ulpadj = 0; - } - else { - denorm = 1; - ulpadj = be + 1; - dbits <<= 1; - if (!(dbits & 0xffffffff00000000ull)) { - dbits <<= 32; - be -= 32; - } - if (!(dbits & 0xffff000000000000ull)) { - dbits <<= 16; - be -= 16; - } - if (!(dbits & 0xff00000000000000ull)) { - dbits <<= 8; - be -= 8; - } - if (!(dbits & 0xf000000000000000ull)) { - dbits <<= 4; - be -= 4; - } - if (!(dbits & 0xc000000000000000ull)) { - dbits <<= 2; - be -= 2; - } - if (!(dbits & 0x8000000000000000ull)) { - dbits <<= 1; - be -= 1; - } - assert(be >= -51); - ulpadj -= be; - } - j = Lhint[be + 51]; - p10 = &pten[j]; - dbhi = dbits >> 32; - dblo = dbits & 0xffffffffull; - i = be - 0x3fe; - if (i < p10->e - || (i == p10->e && (dbhi < p10->b0 || (dbhi == p10->b0 && dblo < p10->b1)))) - --j; - k = j - 342; +#ifdef USE_BF96 /*{{*/ + dbits = (u.LL & 0xfffffffffffffull) << 11; /* fraction bits */ + if ((be = u.LL >> 52)) /* biased exponent; nonzero ==> normal */ { + dbits |= 0x8000000000000000ull; + denorm = ulpadj = 0; + } else { + denorm = 1; + ulpadj = be + 1; + dbits <<= 1; + if (!(dbits & 0xffffffff00000000ull)) { + dbits <<= 32; + be -= 32; + } + if (!(dbits & 0xffff000000000000ull)) { + dbits <<= 16; + be -= 16; + } + if (!(dbits & 0xff00000000000000ull)) { + dbits <<= 8; + be -= 8; + } + if (!(dbits & 0xf000000000000000ull)) { + dbits <<= 4; + be -= 4; + } + if (!(dbits & 0xc000000000000000ull)) { + dbits <<= 2; + be -= 2; + } + if (!(dbits & 0x8000000000000000ull)) { + dbits <<= 1; + be -= 1; + } + assert(be >= -51); + ulpadj -= be; + } + j = kDtoaLhint[be + 51]; + p10 = &kDtoaPten[j]; + dbhi = dbits >> 32; + dblo = dbits & 0xffffffffull; + i = be - 0x3fe; + if (i < p10->e || + (i == p10->e && (dbhi < p10->b0 || (dbhi == p10->b0 && dblo < p10->b1)))) + --j; + k = j - 342; - /* now 10^k <= dd < 10^(k+1) */ + /* now 10^k <= dd < 10^(k+1) */ #else /*}{*/ - b = d2b(&u, &be, &bbits MTb); + b = dtoa_d2b(&u, &be, &bbits MTb); #ifdef Sudden_Underflow - i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); + i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask >> Exp_shift1)); #else - if ((i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)))) { + if ((i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask >> Exp_shift1)))) { #endif - dval(&d2) = dval(&u); - word0(&d2) &= Frac_mask1; - word0(&d2) |= Exp_11; + dval(&d2) = dval(&u); + word0(&d2) &= Frac_mask1; + word0(&d2) |= Exp_11; #ifdef IBM - if (j = 11 - hi0bits(word0(&d2) & Frac_mask)) - dval(&d2) /= 1u << j; + if (j = 11 - dtoa_hi0bits(word0(&d2) & Frac_mask)) dval(&d2) /= 1u << j; #endif - /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 - * log10(x) = log(x) / log(10) - * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) - * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) - * - * This suggests computing an approximation k to log10(d) by - * - * k = (i - Bias)*0.301029995663981 - * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); - * - * We want k to be too large rather than too small. - * The error in the first-order Taylor series approximation - * is in our favor, so we just round up the constant enough - * to compensate for any error in the multiplication of - * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, - * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, - * adding 1e-13 to the constant term more than suffices. - * Hence we adjust the constant term to 0.1760912590558. - * (We could get a more accurate k by invoking log10, - * but this is probably not worthwhile.) - */ + /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 + * log10(x) = log(x) / log(10) + * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10)) + * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2) + * + * This suggests computing an approximation k to log10(d) by + * + * k = (i - Bias)*0.301029995663981 + * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 ); + * + * We want k to be too large rather than too small. + * The error in the first-order Taylor series approximation + * is in our favor, so we just round up the constant enough + * to compensate for any error in the multiplication of + * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077, + * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14, + * adding 1e-13 to the constant term more than suffices. + * Hence we adjust the constant term to 0.1760912590558. + * (We could get a more accurate k by invoking log10, + * but this is probably not worthwhile.) + */ - i -= Bias; + i -= Bias; #ifdef IBM - i <<= 2; - i += j; + i <<= 2; + i += j; #endif #ifndef Sudden_Underflow - denorm = 0; - } - else { - /* d is denormalized */ + denorm = 0; + } + else { + /* d is denormalized */ - i = bbits + be + (Bias + (P-1) - 1); - x = i > 32 ? word0(&u) << (64 - i) | word1(&u) >> (i - 32) - : word1(&u) << (32 - i); - dval(&d2) = x; - word0(&d2) -= 31*Exp_msk1; /* adjust exponent */ - i -= (Bias + (P-1) - 1) + 1; - denorm = 1; - } + i = bbits + be + (Bias + (P - 1) - 1); + x = i > 32 ? word0(&u) << (64 - i) | word1(&u) >> (i - 32) + : word1(&u) << (32 - i); + dval(&d2) = x; + word0(&d2) -= 31 * Exp_msk1; /* adjust exponent */ + i -= (Bias + (P - 1) - 1) + 1; + denorm = 1; + } #endif - ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; - k = (int)ds; - if (ds < 0. && ds != k) - k--; /* want k = floor(ds) */ - k_check = 1; - if (k >= 0 && k <= Ten_pmax) { - if (dval(&u) < tens[k]) - k--; - k_check = 0; - } - j = bbits - i - 1; - if (j >= 0) { - b2 = 0; - s2 = j; - } - else { - b2 = -j; - s2 = 0; - } - if (k >= 0) { - b5 = 0; - s5 = k; - s2 += k; - } - else { - b2 -= k; - b5 = -k; - s5 = 0; - } + ds = (dval(&d2) - 1.5) * 0.289529654602168 + 0.1760912590558 + + i * 0.301029995663981; + k = (int)ds; + if (ds < 0. && ds != k) k--; /* want k = floor(ds) */ + k_check = 1; + if (k >= 0 && k <= Ten_pmax) { + if (dval(&u) < kDtoaTens[k]) k--; + k_check = 0; + } + j = bbits - i - 1; + if (j >= 0) { + b2 = 0; + s2 = j; + } else { + b2 = -j; + s2 = 0; + } + if (k >= 0) { + b5 = 0; + s5 = k; + s2 += k; + } else { + b2 -= k; + b5 = -k; + s5 = 0; + } #endif /*}}*/ - if (mode < 0 || mode > 9) - mode = 0; + if (mode < 0 || mode > 9) mode = 0; #ifndef USE_BF96 #ifndef SET_INEXACT #ifdef Check_FLT_ROUNDS - try_quick = Rounding == 1; + try_quick = Rounding == 1; #endif #endif /*SET_INEXACT*/ #endif - if (mode > 5) { - mode -= 4; + if (mode > 5) { + mode -= 4; #ifndef USE_BF96 - try_quick = 0; + try_quick = 0; #endif - } - leftright = 1; - ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */ - /* silence erroneous "gcc -Wall" warning. */ - switch(mode) { - case 0: - case 1: - i = 18; - ndigits = 0; - break; - case 2: - leftright = 0; - /* no break */ - case 4: - if (ndigits <= 0) - ndigits = 1; - ilim = ilim1 = i = ndigits; - break; - case 3: - leftright = 0; - /* no break */ - case 5: - i = ndigits + k + 1; - ilim = i; - ilim1 = i - 1; - if (i <= 0) - i = 1; - } - if (!buf) { - buf = rv_alloc(i MTb); - blen = sizeof(Bigint) + ((1 << ((int*)buf)[-1]) - 1)*sizeof(ULong) - sizeof(int); - } - else if (blen <= i) { - buf = 0; - if (rve) - *rve = buf + i; - return buf; - } - s = buf; + } + leftright = 1; + ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */ + /* silence erroneous "gcc -Wall" warning. */ + switch (mode) { + case 0: + case 1: + i = 18; + ndigits = 0; + break; + case 2: + leftright = 0; + /* no break */ + case 4: + if (ndigits <= 0) ndigits = 1; + ilim = ilim1 = i = ndigits; + break; + case 3: + leftright = 0; + /* no break */ + case 5: + i = ndigits + k + 1; + ilim = i; + ilim1 = i - 1; + if (i <= 0) i = 1; + } + if (!buf) { + buf = dtoa_rv_alloc(i MTb); + blen = sizeof(Bigint) + ((1 << ((int *)buf)[-1]) - 1) * sizeof(ULong) - + sizeof(int); + } else if (blen <= i) { + buf = 0; + if (rve) *rve = buf + i; + return buf; + } + s = buf; - /* Check for special case that d is a normalized power of 2. */ + /* Check for special case that d is a normalized power of 2. */ - spec_case = 0; - if (mode < 2 || (leftright + spec_case = 0; + if (mode < 2 || (leftright #ifdef Honor_FLT_ROUNDS - && Rounding == 1 + && Rounding == 1 #endif - )) { - if (!word1(&u) && !(word0(&u) & Bndry_mask) + )) { + if (!word1(&u) && !(word0(&u) & Bndry_mask) #ifndef Sudden_Underflow - && word0(&u) & (Exp_mask & ~Exp_msk1) + && word0(&u) & (Exp_mask & ~Exp_msk1) #endif - ) { - /* The special case */ - spec_case = 1; - } - } + ) { + /* The special case */ + spec_case = 1; + } + } #ifdef USE_BF96 /*{*/ - b = 0; - if (ilim < 0 && (mode == 3 || mode == 5)) { - S = mhi = 0; - goto no_digits; - } - i = 1; - j = 52 + 0x3ff - be; - ulpshift = 0; - ulplo = 0; - /* Can we do an exact computation with 64-bit integer arithmetic? */ - if (k < 0) { - if (k < -25) - goto toobig; - res = dbits >> 11; - n2 = pfivebits[k1 = -(k + 1)] + 53; - j1 = j; - if (n2 > 61) { - ulpshift = n2 - 61; - if (res & (ulpmask = (1ull << ulpshift) - 1)) - goto toobig; - j -= ulpshift; - res >>= ulpshift; - } - /* Yes. */ - res *= ulp = pfive[k1]; - if (ulpshift) { - ulplo = ulp; - ulp >>= ulpshift; - } - j += k; - if (ilim == 0) { - S = mhi = 0; - if (res > (5ull << j)) - goto one_digit; - goto no_digits; - } - goto no_div; - } - if (ilim == 0 && j + k >= 0) { - S = mhi = 0; - if ((dbits >> 11) > (pfive[k-1] << j)) - goto one_digit; - goto no_digits; - } - if (k <= dtoa_divmax && j + k >= 0) { - /* Another "yes" case -- we will use exact integer arithmetic. */ - use_exact: - Debug(++dtoa_stats[3]); - res = dbits >> 11; /* residual */ - ulp = 1; - if (k <= 0) - goto no_div; - j1 = j + k + 1; - den = pfive[k-i] << (j1 - i); - for(;;) { - dig = res / den; - *s++ = '0' + dig; - if (!(res -= dig*den)) { + b = 0; + if (ilim < 0 && (mode == 3 || mode == 5)) { + S = mhi = 0; + goto no_digits; + } + i = 1; + j = 52 + 0x3ff - be; + ulpshift = 0; + ulplo = 0; + /* Can we do an exact computation with 64-bit integer arithmetic? */ + if (k < 0) { + if (k < -25) goto toobig; + res = dbits >> 11; + n2 = kDtoaPfiveBits[k1 = -(k + 1)] + 53; + j1 = j; + if (n2 > 61) { + ulpshift = n2 - 61; + if (res & (ulpmask = (1ull << ulpshift) - 1)) goto toobig; + j -= ulpshift; + res >>= ulpshift; + } + /* Yes. */ + res *= ulp = kDtoaPfive[k1]; + if (ulpshift) { + ulplo = ulp; + ulp >>= ulpshift; + } + j += k; + if (ilim == 0) { + S = mhi = 0; + if (res > (5ull << j)) goto one_digit; + goto no_digits; + } + goto no_div; + } + if (ilim == 0 && j + k >= 0) { + S = mhi = 0; + if ((dbits >> 11) > (kDtoaPfive[k - 1] << j)) goto one_digit; + goto no_digits; + } + if (k <= dtoa_divmax && j + k >= 0) { + /* Another "yes" case -- we will use exact integer arithmetic. */ + use_exact: + Debug(++dtoa_stats[3]); + res = dbits >> 11; /* residual */ + ulp = 1; + if (k <= 0) goto no_div; + j1 = j + k + 1; + den = kDtoaPfive[k - i] << (j1 - i); + for (;;) { + dig = res / den; + *s++ = '0' + dig; + if (!(res -= dig * den)) { #ifdef SET_INEXACT - inexact = 0; - oldinexact = 1; + inexact = 0; + oldinexact = 1; #endif - goto retc; - } - if (ilim < 0) { - ures = den - res; - if (2*res <= ulp - && (spec_case ? 4*res <= ulp : (2*res < ulp || dig & 1))) - goto ulp_reached; - if (2*ures < ulp) - goto Roundup; - } - else if (i == ilim) { - switch(Rounding) { - case 0: goto retc; - case 2: goto Roundup; - default: (void)0; /* added by jart */ - } - ures = 2*res; - if (ures > den - || (ures == den && dig & 1) - || (spec_case && res <= ulp && 2*res >= ulp)) - goto Roundup; - goto retc; - } - if (j1 < ++i) { - res *= 10; - ulp *= 10; - } - else { - if (i > k) - break; - den = pfive[k-i] << (j1 - i); - } - } - no_div: - for(;;) { - dig = den = res >> j; - *s++ = '0' + dig; - if (!(res -= den << j)) { + goto retc; + } + if (ilim < 0) { + ures = den - res; + if (2 * res <= ulp && + (spec_case ? 4 * res <= ulp : (2 * res < ulp || dig & 1))) + goto ulp_reached; + if (2 * ures < ulp) goto Roundup; + } else if (i == ilim) { + switch (Rounding) { + case 0: + goto retc; + case 2: + goto Roundup; + default: + (void)0; /* added by jart */ + } + ures = 2 * res; + if (ures > den || (ures == den && dig & 1) || + (spec_case && res <= ulp && 2 * res >= ulp)) + goto Roundup; + goto retc; + } + if (j1 < ++i) { + res *= 10; + ulp *= 10; + } else { + if (i > k) break; + den = kDtoaPfive[k - i] << (j1 - i); + } + } + no_div: + for (;;) { + dig = den = res >> j; + *s++ = '0' + dig; + if (!(res -= den << j)) { #ifdef SET_INEXACT - inexact = 0; - oldinexact = 1; + inexact = 0; + oldinexact = 1; #endif - goto retc; - } - if (ilim < 0) { - ures = (1ull << j) - res; - if (2*res <= ulp - && (spec_case ? 4*res <= ulp : (2*res < ulp || dig & 1))) { - ulp_reached: - if (ures < res - || (ures == res && dig & 1)) - goto Roundup; - goto retc; - } - if (2*ures < ulp) - goto Roundup; - } - --j; - if (i == ilim) { + goto retc; + } + if (ilim < 0) { + ures = (1ull << j) - res; + if (2 * res <= ulp && + (spec_case ? 4 * res <= ulp : (2 * res < ulp || dig & 1))) { + ulp_reached: + if (ures < res || (ures == res && dig & 1)) goto Roundup; + goto retc; + } + if (2 * ures < ulp) goto Roundup; + } + --j; + if (i == ilim) { #ifdef Honor_FLT_ROUNDS - switch(Rounding) { - case 0: goto retc; - case 2: goto Roundup; - } + switch (Rounding) { + case 0: + goto retc; + case 2: + goto Roundup; + } #endif - hb = 1ull << j; - if (res & hb && (dig & 1 || res & (hb-1))) - goto Roundup; - if (spec_case && res <= ulp && 2*res >= ulp) { - Roundup: - while(*--s == '9') - if (s == buf) { - ++k; - *s++ = '1'; - goto ret1; - } - ++*s++; - goto ret1; - } - goto retc; - } - ++i; - res *= 5; - if (ulpshift) { - ulplo = 5*(ulplo & ulpmask); - ulp = 5*ulp + (ulplo >> ulpshift); - } - else - ulp *= 5; - } - } - toobig: - if (ilim > 28) - goto Fast_failed1; - /* Scale by 10^-k */ - p10 = &pten[342-k]; - tv0 = p10->b2 * dblo; /* rarely matters, but does, e.g., for 9.862818194192001e18 */ - tv1 = p10->b1 * dblo + (tv0 >> 32); - tv2 = p10->b2 * dbhi + (tv1 & 0xffffffffull); - tv3 = p10->b0 * dblo + (tv1>>32) + (tv2>>32); - res3 = p10->b1 * dbhi + (tv3 & 0xffffffffull); - res = p10->b0 * dbhi + (tv3>>32) + (res3>>32); - be += p10->e - 0x3fe; - eulp = j1 = be - 54 + ulpadj; - if (!(res & 0x8000000000000000ull)) { - --be; - res3 <<= 1; - res = (res << 1) | ((res3 & 0x100000000ull) >> 32); - } - res0 = res; /* save for Fast_failed */ + hb = 1ull << j; + if (res & hb && (dig & 1 || res & (hb - 1))) goto Roundup; + if (spec_case && res <= ulp && 2 * res >= ulp) { + Roundup: + while (*--s == '9') + if (s == buf) { + ++k; + *s++ = '1'; + goto ret1; + } + ++*s++; + goto ret1; + } + goto retc; + } + ++i; + res *= 5; + if (ulpshift) { + ulplo = 5 * (ulplo & ulpmask); + ulp = 5 * ulp + (ulplo >> ulpshift); + } else + ulp *= 5; + } + } +toobig: + if (ilim > 28) goto Fast_failed1; + /* Scale by 10^-k */ + p10 = &kDtoaPten[342 - k]; + tv0 = p10->b2 * + dblo; /* rarely matters, but does, e.g., for 9.862818194192001e18 */ + tv1 = p10->b1 * dblo + (tv0 >> 32); + tv2 = p10->b2 * dbhi + (tv1 & 0xffffffffull); + tv3 = p10->b0 * dblo + (tv1 >> 32) + (tv2 >> 32); + res3 = p10->b1 * dbhi + (tv3 & 0xffffffffull); + res = p10->b0 * dbhi + (tv3 >> 32) + (res3 >> 32); + be += p10->e - 0x3fe; + eulp = j1 = be - 54 + ulpadj; + if (!(res & 0x8000000000000000ull)) { + --be; + res3 <<= 1; + res = (res << 1) | ((res3 & 0x100000000ull) >> 32); + } + res0 = res; /* save for Fast_failed */ #if !defined(SET_INEXACT) && !defined(NO_DTOA_64) /*{*/ - if (ilim > 19) - goto Fast_failed; - Debug(++dtoa_stats[4]); - assert(be >= 0 && be <= 4); /* be = 0 is rare, but possible, e.g., for 1e20 */ - res >>= 4 - be; - ulp = p10->b0; /* ulp */ - ulp = (ulp << 29) | (p10->b1 >> 3); - /* scaled ulp = ulp * 2^(eulp - 60) */ - /* We maintain 61 bits of the scaled ulp. */ - if (ilim == 0) { - if (!(res & 0x7fffffffffffffeull) - || !((~res) & 0x7fffffffffffffeull)) - goto Fast_failed1; - S = mhi = 0; - if (res >= 0x5000000000000000ull) - goto one_digit; - goto no_digits; - } - rb = 1; /* upper bound on rounding error */ - for(;;++i) { - dig = res >> 60; - *s++ = '0' + dig; - res &= 0xfffffffffffffffull; - if (ilim < 0) { - ures = 0x1000000000000000ull - res; - if (eulp > 0) { - assert(eulp <= 4); - sulp = ulp << (eulp - 1); - if (res <= ures) { - if (res + rb > ures - rb) - goto Fast_failed; - if (res < sulp) - goto retc; - } - else { - if (res - rb <= ures + rb) - goto Fast_failed; - if (ures < sulp) - goto Roundup; - } - } - else { - zb = -(1ull << (eulp + 63)); - if (!(zb & res)) { - sres = res << (1 - eulp); - if (sres < ulp && (!spec_case || 2*sres < ulp)) { - if ((res+rb) << (1 - eulp) >= ulp) - goto Fast_failed; - if (ures < res) { - if (ures + rb >= res - rb) - goto Fast_failed; - goto Roundup; - } - if (ures - rb < res + rb) - goto Fast_failed; - goto retc; - } - } - if (!(zb & ures) && ures << -eulp < ulp) { - if (ures << (1 - eulp) < ulp) - goto Roundup; - goto Fast_failed; - } - } - } - else if (i == ilim) { - ures = 0x1000000000000000ull - res; - if (ures < res) { - if (ures <= rb || res - rb <= ures + rb) { - if (j + k >= 0 && k >= 0 && k <= 27) - goto use_exact1; - goto Fast_failed; - } + if (ilim > 19) goto Fast_failed; + Debug(++dtoa_stats[4]); + assert(be >= 0 && be <= 4); /* be = 0 is rare, but possible, e.g., for 1e20 */ + res >>= 4 - be; + ulp = p10->b0; /* ulp */ + ulp = (ulp << 29) | (p10->b1 >> 3); + /* scaled ulp = ulp * 2^(eulp - 60) */ + /* We maintain 61 bits of the scaled ulp. */ + if (ilim == 0) { + if (!(res & 0x7fffffffffffffeull) || !((~res) & 0x7fffffffffffffeull)) + goto Fast_failed1; + S = mhi = 0; + if (res >= 0x5000000000000000ull) goto one_digit; + goto no_digits; + } + rb = 1; /* upper bound on rounding error */ + for (;; ++i) { + dig = res >> 60; + *s++ = '0' + dig; + res &= 0xfffffffffffffffull; + if (ilim < 0) { + ures = 0x1000000000000000ull - res; + if (eulp > 0) { + assert(eulp <= 4); + dtoa_sulp = ulp << (eulp - 1); + if (res <= ures) { + if (res + rb > ures - rb) goto Fast_failed; + if (res < dtoa_sulp) goto retc; + } else { + if (res - rb <= ures + rb) goto Fast_failed; + if (ures < dtoa_sulp) goto Roundup; + } + } else { + zb = -(1ull << (eulp + 63)); + if (!(zb & res)) { + sres = res << (1 - eulp); + if (sres < ulp && (!spec_case || 2 * sres < ulp)) { + if ((res + rb) << (1 - eulp) >= ulp) goto Fast_failed; + if (ures < res) { + if (ures + rb >= res - rb) goto Fast_failed; + goto Roundup; + } + if (ures - rb < res + rb) goto Fast_failed; + goto retc; + } + } + if (!(zb & ures) && ures << -eulp < ulp) { + if (ures << (1 - eulp) < ulp) goto Roundup; + goto Fast_failed; + } + } + } else if (i == ilim) { + ures = 0x1000000000000000ull - res; + if (ures < res) { + if (ures <= rb || res - rb <= ures + rb) { + if (j + k >= 0 && k >= 0 && k <= 27) goto use_exact1; + goto Fast_failed; + } #ifdef Honor_FLT_ROUNDS - if (Rounding == 0) - goto retc; + if (Rounding == 0) goto retc; #endif - goto Roundup; - } - if (res <= rb || ures - rb <= res + rb) { - if (j + k >= 0 && k >= 0 && k <= 27) { - use_exact1: - s = buf; - i = 1; - goto use_exact; - } - goto Fast_failed; - } + goto Roundup; + } + if (res <= rb || ures - rb <= res + rb) { + if (j + k >= 0 && k >= 0 && k <= 27) { + use_exact1: + s = buf; + i = 1; + goto use_exact; + } + goto Fast_failed; + } #ifdef Honor_FLT_ROUNDS - if (Rounding == 2) - goto Roundup; + if (Rounding == 2) goto Roundup; #endif - goto retc; - } - rb *= 10; - if (rb >= 0x1000000000000000ull) - goto Fast_failed; - res *= 10; - ulp *= 5; - if (ulp & 0x8000000000000000ull) { - eulp += 4; - ulp >>= 3; - } - else { - eulp += 3; - ulp >>= 2; - } - } + goto retc; + } + rb *= 10; + if (rb >= 0x1000000000000000ull) goto Fast_failed; + res *= 10; + ulp *= 5; + if (ulp & 0x8000000000000000ull) { + eulp += 4; + ulp >>= 3; + } else { + eulp += 3; + ulp >>= 2; + } + } #endif /*}*/ #ifndef NO_BF96 - Fast_failed: +Fast_failed: #endif - Debug(++dtoa_stats[5]); - s = buf; - i = 4 - be; - res = res0 >> i; - reslo = 0xffffffffull & res3; - if (i) - reslo = (res0 << (64 - i)) >> 32 | (reslo >> i); - rb = 0; - rblo = 4; /* roundoff bound */ - ulp = p10->b0; /* ulp */ - ulp = (ulp << 29) | (p10->b1 >> 3); - eulp = j1; - for(i = 1;;++i) { - dig = res >> 60; - *s++ = '0' + dig; - res &= 0xfffffffffffffffull; + Debug(++dtoa_stats[5]); + s = buf; + i = 4 - be; + res = res0 >> i; + reslo = 0xffffffffull & res3; + if (i) reslo = (res0 << (64 - i)) >> 32 | (reslo >> i); + rb = 0; + rblo = 4; /* roundoff bound */ + ulp = p10->b0; /* ulp */ + ulp = (ulp << 29) | (p10->b1 >> 3); + eulp = j1; + for (i = 1;; ++i) { + dig = res >> 60; + *s++ = '0' + dig; + res &= 0xfffffffffffffffull; #ifdef SET_INEXACT - if (!res && !reslo) { - if (!(res3 & 0xffffffffull)) { - inexact = 0; - oldinexact = 1; - } - goto retc; - } + if (!res && !reslo) { + if (!(res3 & 0xffffffffull)) { + inexact = 0; + oldinexact = 1; + } + goto retc; + } #endif - if (ilim < 0) { - ures = 0x1000000000000000ull - res; - ureslo = 0; - if (reslo) { - ureslo = 0x100000000ull - reslo; - --ures; - } - if (eulp > 0) { - assert(eulp <= 4); - sulp = (ulp << (eulp - 1)) - rb; - if (res <= ures) { - if (res < sulp) { - if (res+rb < ures-rb) - goto retc; - } - } - else if (ures < sulp) { - if (res-rb > ures+rb) - goto Roundup; - } - goto Fast_failed1; - } - else { - zb = -(1ull << (eulp + 60)); - if (!(zb & (res + rb))) { - sres = (res - rb) << (1 - eulp); - if (sres < ulp && (!spec_case || 2*sres < ulp)) { - sres = res << (1 - eulp); - if ((j = eulp + 31) > 0) - sres += (rblo + reslo) >> j; - else - sres += (rblo + reslo) << -j; - if (sres + (rb << (1 - eulp)) >= ulp) - goto Fast_failed1; - if (sres >= ulp) - goto more96; - if (ures < res - || (ures == res && ureslo < reslo)) { - if (ures + rb >= res - rb) - goto Fast_failed1; - goto Roundup; - } - if (ures - rb <= res + rb) - goto Fast_failed1; - goto retc; - } - } - if (!(zb & ures) && (ures-rb) << (1 - eulp) < ulp) { - if ((ures + rb) << (1 - eulp) < ulp) - goto Roundup; - goto Fast_failed1; - } - } - } - else if (i == ilim) { - ures = 0x1000000000000000ull - res; - sres = ureslo = 0; - if (reslo) { - ureslo = 0x100000000ull - reslo; - --ures; - sres = (reslo + rblo) >> 31; - } - sres += 2*rb; - if (ures <= res) { - if (ures <=sres || res - ures <= sres) - goto Fast_failed1; + if (ilim < 0) { + ures = 0x1000000000000000ull - res; + ureslo = 0; + if (reslo) { + ureslo = 0x100000000ull - reslo; + --ures; + } + if (eulp > 0) { + assert(eulp <= 4); + dtoa_sulp = (ulp << (eulp - 1)) - rb; + if (res <= ures) { + if (res < dtoa_sulp) { + if (res + rb < ures - rb) goto retc; + } + } else if (ures < dtoa_sulp) { + if (res - rb > ures + rb) goto Roundup; + } + goto Fast_failed1; + } else { + zb = -(1ull << (eulp + 60)); + if (!(zb & (res + rb))) { + sres = (res - rb) << (1 - eulp); + if (sres < ulp && (!spec_case || 2 * sres < ulp)) { + sres = res << (1 - eulp); + if ((j = eulp + 31) > 0) + sres += (rblo + reslo) >> j; + else + sres += (rblo + reslo) << -j; + if (sres + (rb << (1 - eulp)) >= ulp) goto Fast_failed1; + if (sres >= ulp) goto more96; + if (ures < res || (ures == res && ureslo < reslo)) { + if (ures + rb >= res - rb) goto Fast_failed1; + goto Roundup; + } + if (ures - rb <= res + rb) goto Fast_failed1; + goto retc; + } + } + if (!(zb & ures) && (ures - rb) << (1 - eulp) < ulp) { + if ((ures + rb) << (1 - eulp) < ulp) goto Roundup; + goto Fast_failed1; + } + } + } else if (i == ilim) { + ures = 0x1000000000000000ull - res; + sres = ureslo = 0; + if (reslo) { + ureslo = 0x100000000ull - reslo; + --ures; + sres = (reslo + rblo) >> 31; + } + sres += 2 * rb; + if (ures <= res) { + if (ures <= sres || res - ures <= sres) goto Fast_failed1; #ifdef Honor_FLT_ROUNDS - if (Rounding == 0) - goto retc; + if (Rounding == 0) goto retc; #endif - goto Roundup; - } - if (res <= sres || ures - res <= sres) - goto Fast_failed1; + goto Roundup; + } + if (res <= sres || ures - res <= sres) goto Fast_failed1; #ifdef Honor_FLT_ROUNDS - if (Rounding == 2) - goto Roundup; + if (Rounding == 2) goto Roundup; #endif - goto retc; - } - more96: - rblo *= 10; - rb = 10*rb + (rblo >> 32); - rblo &= 0xffffffffull; - if (rb >= 0x1000000000000000ull) - goto Fast_failed1; - reslo *= 10; - res = 10*res + (reslo >> 32); - reslo &= 0xffffffffull; - ulp *= 5; - if (ulp & 0x8000000000000000ull) { - eulp += 4; - ulp >>= 3; - } - else { - eulp += 3; - ulp >>= 2; - } - } - Fast_failed1: - Debug(++dtoa_stats[6]); - S = mhi = mlo = 0; + goto retc; + } + more96: + rblo *= 10; + rb = 10 * rb + (rblo >> 32); + rblo &= 0xffffffffull; + if (rb >= 0x1000000000000000ull) goto Fast_failed1; + reslo *= 10; + res = 10 * res + (reslo >> 32); + reslo &= 0xffffffffull; + ulp *= 5; + if (ulp & 0x8000000000000000ull) { + eulp += 4; + ulp >>= 3; + } else { + eulp += 3; + ulp >>= 2; + } + } +Fast_failed1: + Debug(++dtoa_stats[6]); + S = mhi = mlo = 0; #ifdef USE_BF96 - b = d2b(&u, &be, &bbits MTb); + b = dtoa_d2b(&u, &be, &bbits MTb); #endif - s = buf; - i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); - i -= Bias; - if (ulpadj) - i -= ulpadj - 1; - j = bbits - i - 1; - if (j >= 0) { - b2 = 0; - s2 = j; - } - else { - b2 = -j; - s2 = 0; - } - if (k >= 0) { - b5 = 0; - s5 = k; - s2 += k; - } - else { - b2 -= k; - b5 = -k; - s5 = 0; - } + s = buf; + i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask >> Exp_shift1)); + i -= Bias; + if (ulpadj) i -= ulpadj - 1; + j = bbits - i - 1; + if (j >= 0) { + b2 = 0; + s2 = j; + } else { + b2 = -j; + s2 = 0; + } + if (k >= 0) { + b5 = 0; + s5 = k; + s2 += k; + } else { + b2 -= k; + b5 = -k; + s5 = 0; + } #endif /*}*/ #ifdef Honor_FLT_ROUNDS - if (mode > 1 && Rounding != 1) - leftright = 0; + if (mode > 1 && Rounding != 1) leftright = 0; #endif #ifndef USE_BF96 /*{*/ - if (ilim >= 0 && ilim <= Quick_max && try_quick) { + if (ilim >= 0 && ilim <= Quick_max && try_quick) { - /* Try to get by with floating-point arithmetic. */ + /* Try to get by with floating-point arithmetic. */ - i = 0; - dval(&d2) = dval(&u); - j1 = -(k0 = k); - ilim0 = ilim; - ieps = 2; /* conservative */ - if (k > 0) { - ds = tens[k&0xf]; - j = k >> 4; - if (j & Bletch) { - /* prevent overflows */ - j &= Bletch - 1; - dval(&u) /= bigtens[n_bigtens-1]; - ieps++; - } - for(; j; j >>= 1, i++) - if (j & 1) { - ieps++; - ds *= bigtens[i]; - } - dval(&u) /= ds; - } - else if (j1 > 0) { - dval(&u) *= tens[j1 & 0xf]; - for(j = j1 >> 4; j; j >>= 1, i++) - if (j & 1) { - ieps++; - dval(&u) *= bigtens[i]; - } - } - if (k_check && dval(&u) < 1. && ilim > 0) { - if (ilim1 <= 0) - goto fast_failed; - ilim = ilim1; - k--; - dval(&u) *= 10.; - ieps++; - } - dval(&eps) = ieps*dval(&u) + 7.; - word0(&eps) -= (P-1)*Exp_msk1; - if (ilim == 0) { - S = mhi = 0; - dval(&u) -= 5.; - if (dval(&u) > dval(&eps)) - goto one_digit; - if (dval(&u) < -dval(&eps)) - goto no_digits; - goto fast_failed; - } + i = 0; + dval(&d2) = dval(&u); + j1 = -(k0 = k); + ilim0 = ilim; + ieps = 2; /* conservative */ + if (k > 0) { + ds = kDtoaTens[k & 0xf]; + j = k >> 4; + if (j & Bletch) { + /* prevent overflows */ + j &= Bletch - 1; + dval(&u) /= kDtoaBigTens[n_bigtens - 1]; + ieps++; + } + for (; j; j >>= 1, i++) + if (j & 1) { + ieps++; + ds *= kDtoaBigTens[i]; + } + dval(&u) /= ds; + } else if (j1 > 0) { + dval(&u) *= kDtoaTens[j1 & 0xf]; + for (j = j1 >> 4; j; j >>= 1, i++) + if (j & 1) { + ieps++; + dval(&u) *= kDtoaBigTens[i]; + } + } + if (k_check && dval(&u) < 1. && ilim > 0) { + if (ilim1 <= 0) goto fast_failed; + ilim = ilim1; + k--; + dval(&u) *= 10.; + ieps++; + } + dval(&eps) = ieps * dval(&u) + 7.; + word0(&eps) -= (P - 1) * Exp_msk1; + if (ilim == 0) { + S = mhi = 0; + dval(&u) -= 5.; + if (dval(&u) > dval(&eps)) goto one_digit; + if (dval(&u) < -dval(&eps)) goto no_digits; + goto fast_failed; + } #ifndef No_leftright - if (leftright) { - /* Use Steele & White method of only - * generating digits needed. - */ - dval(&eps) = 0.5/tens[ilim-1] - dval(&eps); + if (leftright) { + /* Use Steele & White method of only + * generating digits needed. + */ + dval(&eps) = 0.5 / kDtoaTens[ilim - 1] - dval(&eps); #ifdef IEEE_Arith - if (j1 >= 307) { - eps1.d = 1.01e256; /* 1.01 allows roundoff in the next few lines */ - word0(&eps1) -= Exp_msk1 * (Bias+P-1); - dval(&eps1) *= tens[j1 & 0xf]; - for(i = 0, j = (j1-256) >> 4; j; j >>= 1, i++) - if (j & 1) - dval(&eps1) *= bigtens[i]; - if (eps.d < eps1.d) - eps.d = eps1.d; - if (10. - u.d < 10.*eps.d && eps.d < 1.) { - /* eps.d < 1. excludes trouble with the tiniest denormal */ - *s++ = '1'; - ++k; - goto ret1; - } - } + if (j1 >= 307) { + eps1.d = 1.01e256; /* 1.01 allows roundoff in the next few lines */ + word0(&eps1) -= Exp_msk1 * (Bias + P - 1); + dval(&eps1) *= kDtoaTens[j1 & 0xf]; + for (i = 0, j = (j1 - 256) >> 4; j; j >>= 1, i++) + if (j & 1) dval(&eps1) *= kDtoaBigTens[i]; + if (eps.d < eps1.d) eps.d = eps1.d; + if (10. - u.d < 10. * eps.d && eps.d < 1.) { + /* eps.d < 1. excludes trouble with the tiniest denormal */ + *s++ = '1'; + ++k; + goto ret1; + } + } #endif - for(i = 0;;) { - L = dval(&u); - dval(&u) -= L; - *s++ = '0' + (int)L; - if (1. - dval(&u) < dval(&eps)) - goto bump_up; - if (dval(&u) < dval(&eps)) - goto retc; - if (++i >= ilim) - break; - dval(&eps) *= 10.; - dval(&u) *= 10.; - } - } - else { + for (i = 0;;) { + L = dval(&u); + dval(&u) -= L; + *s++ = '0' + (int)L; + if (1. - dval(&u) < dval(&eps)) goto bump_up; + if (dval(&u) < dval(&eps)) goto retc; + if (++i >= ilim) break; + dval(&eps) *= 10.; + dval(&u) *= 10.; + } + } else { #endif - /* Generate ilim digits, then fix them up. */ - dval(&eps) *= tens[ilim-1]; - for(i = 1;; i++, dval(&u) *= 10.) { - L = (Long)(dval(&u)); - if (!(dval(&u) -= L)) - ilim = i; - *s++ = '0' + (int)L; - if (i == ilim) { - if (dval(&u) > 0.5 + dval(&eps)) - goto bump_up; - else if (dval(&u) < 0.5 - dval(&eps)) - goto retc; - break; - } - } + /* Generate ilim digits, then fix them up. */ + dval(&eps) *= kDtoaTens[ilim - 1]; + for (i = 1;; i++, dval(&u) *= 10.) { + L = (Long)(dval(&u)); + if (!(dval(&u) -= L)) ilim = i; + *s++ = '0' + (int)L; + if (i == ilim) { + if (dval(&u) > 0.5 + dval(&eps)) + goto bump_up; + else if (dval(&u) < 0.5 - dval(&eps)) + goto retc; + break; + } + } #ifndef No_leftright - } + } #endif - fast_failed: - s = buf; - dval(&u) = dval(&d2); - k = k0; - ilim = ilim0; - } + fast_failed: + s = buf; + dval(&u) = dval(&d2); + k = k0; + ilim = ilim0; + } - /* Do we have a "small" integer? */ + /* Do we have a "small" integer? */ - if (be >= 0 && k <= Int_max) { - /* Yes. */ - ds = tens[k]; - if (ndigits < 0 && ilim <= 0) { - S = mhi = 0; - if (ilim < 0 || dval(&u) <= 5*ds) - goto no_digits; - goto one_digit; - } - for(i = 1;; i++, dval(&u) *= 10.) { - L = (Long)(dval(&u) / ds); - dval(&u) -= L*ds; + if (be >= 0 && k <= Int_max) { + /* Yes. */ + ds = kDtoaTens[k]; + if (ndigits < 0 && ilim <= 0) { + S = mhi = 0; + if (ilim < 0 || dval(&u) <= 5 * ds) goto no_digits; + goto one_digit; + } + for (i = 1;; i++, dval(&u) *= 10.) { + L = (Long)(dval(&u) / ds); + dval(&u) -= L * ds; #ifdef Check_FLT_ROUNDS - /* If FLT_ROUNDS == 2, L will usually be high by 1 */ - if (dval(&u) < 0) { - L--; - dval(&u) += ds; - } + /* If FLT_ROUNDS == 2, L will usually be high by 1 */ + if (dval(&u) < 0) { + L--; + dval(&u) += ds; + } #endif - *s++ = '0' + (int)L; - if (!dval(&u)) { + *s++ = '0' + (int)L; + if (!dval(&u)) { #ifdef SET_INEXACT - inexact = 0; + inexact = 0; #endif - break; - } - if (i == ilim) { + break; + } + if (i == ilim) { #ifdef Honor_FLT_ROUNDS - if (mode > 1) - switch(Rounding) { - case 0: goto retc; - case 2: goto bump_up; - } + if (mode > 1) switch (Rounding) { + case 0: + goto retc; + case 2: + goto bump_up; + } #endif - dval(&u) += dval(&u); + dval(&u) += dval(&u); #ifdef ROUND_BIASED - if (dval(&u) >= ds) + if (dval(&u) >= ds) #else - if (dval(&u) > ds || (dval(&u) == ds && L & 1)) + if (dval(&u) > ds || (dval(&u) == ds && L & 1)) #endif - { - bump_up: - while(*--s == '9') - if (s == buf) { - k++; - *s = '0'; - break; - } - ++*s++; - } - break; - } - } - goto retc; - } + { + bump_up: + while (*--s == '9') + if (s == buf) { + k++; + *s = '0'; + break; + } + ++*s++; + } + break; + } + } + goto retc; + } #endif /*}*/ - m2 = b2; - m5 = b5; - mhi = mlo = 0; - if (leftright) { - i = + m2 = b2; + m5 = b5; + mhi = mlo = 0; + if (leftright) { + i = #ifndef Sudden_Underflow - denorm ? be + (Bias + (P-1) - 1 + 1) : + denorm ? be + (Bias + (P - 1) - 1 + 1) : #endif #ifdef IBM - 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3); + 1 + 4 * P - 3 - bbits + ((bbits + be - 1) & 3); #else - 1 + P - bbits; + 1 + P - bbits; #endif - b2 += i; - s2 += i; - mhi = i2b(1 MTb); - } - if (m2 > 0 && s2 > 0) { - i = m2 < s2 ? m2 : s2; - b2 -= i; - m2 -= i; - s2 -= i; - } - if (b5 > 0) { - if (leftright) { - if (m5 > 0) { - mhi = pow5mult(mhi, m5 MTb); - b1 = mult(mhi, b MTb); - Bfree(b MTb); - b = b1; - } - if ((j = b5 - m5)) - b = pow5mult(b, j MTb); - } - else - b = pow5mult(b, b5 MTb); - } - S = i2b(1 MTb); - if (s5 > 0) - S = pow5mult(S, s5 MTb); + b2 += i; + s2 += i; + mhi = dtoa_i2b(1 MTb); + } + if (m2 > 0 && s2 > 0) { + i = m2 < s2 ? m2 : s2; + b2 -= i; + m2 -= i; + s2 -= i; + } + if (b5 > 0) { + if (leftright) { + if (m5 > 0) { + mhi = dtoa_pow5mult(mhi, m5 MTb); + b1 = dtoa_mult(mhi, b MTb); + dtoa_bfree(b MTb); + b = b1; + } + if ((j = b5 - m5)) b = dtoa_pow5mult(b, j MTb); + } else + b = dtoa_pow5mult(b, b5 MTb); + } + S = dtoa_i2b(1 MTb); + if (s5 > 0) S = dtoa_pow5mult(S, s5 MTb); - if (spec_case) { - b2 += Log2P; - s2 += Log2P; - } + if (spec_case) { + b2 += Log2P; + s2 += Log2P; + } - /* Arrange for convenient computation of quotients: - * shift left if necessary so divisor has 4 leading 0 bits. - * - * Perhaps we should just compute leading 28 bits of S once - * and for all and pass them and a shift to quorem, so it - * can do shifts and ors to compute the numerator for q. - */ - i = dshift(S, s2); - b2 += i; - m2 += i; - s2 += i; - if (b2 > 0) - b = lshift(b, b2 MTb); - if (s2 > 0) - S = lshift(S, s2 MTb); + /* Arrange for convenient computation of quotients: + * shift left if necessary so divisor has 4 leading 0 bits. + * + * Perhaps we should just compute leading 28 bits of S once + * and for all and pass them and a shift to dtoa_quorem, so it + * can do shifts and ors to compute the numerator for q. + */ + i = dtoa_dshift(S, s2); + b2 += i; + m2 += i; + s2 += i; + if (b2 > 0) b = dtoa_lshift(b, b2 MTb); + if (s2 > 0) S = dtoa_lshift(S, s2 MTb); #ifndef USE_BF96 - if (k_check) { - if (cmp(b,S) < 0) { - k--; - b = multadd(b, 10, 0 MTb); /* we botched the k estimate */ - if (leftright) - mhi = multadd(mhi, 10, 0 MTb); - ilim = ilim1; - } - } + if (k_check) { + if (dtoa_cmp(b, S) < 0) { + k--; + b = dtoa_multadd(b, 10, 0 MTb); /* we botched the k estimate */ + if (leftright) mhi = dtoa_multadd(mhi, 10, 0 MTb); + ilim = ilim1; + } + } #endif - if (ilim <= 0 && (mode == 3 || mode == 5)) { - if (ilim < 0 || cmp(b,S = multadd(S,5,0 MTb)) <= 0) { - /* no digits, fcvt style */ - no_digits: - k = -1 - ndigits; - goto ret; - } - one_digit: - *s++ = '1'; - ++k; - goto ret; - } - if (leftright) { - if (m2 > 0) - mhi = lshift(mhi, m2 MTb); + if (ilim <= 0 && (mode == 3 || mode == 5)) { + if (ilim < 0 || dtoa_cmp(b, S = dtoa_multadd(S, 5, 0 MTb)) <= 0) { + /* no digits, fcvt style */ + no_digits: + k = -1 - ndigits; + goto ret; + } + one_digit: + *s++ = '1'; + ++k; + goto ret; + } + if (leftright) { + if (m2 > 0) mhi = dtoa_lshift(mhi, m2 MTb); - /* Compute mlo -- check for special case - * that d is a normalized power of 2. - */ + /* Compute mlo -- check for special case + * that d is a normalized power of 2. + */ - mlo = mhi; - if (spec_case) { - mhi = Balloc(mhi->k MTb); - Bcopy(mhi, mlo); - mhi = lshift(mhi, Log2P MTb); - } + mlo = mhi; + if (spec_case) { + mhi = dtoa_balloc(mhi->k MTb); + Bcopy(mhi, mlo); + mhi = dtoa_lshift(mhi, Log2P MTb); + } - for(i = 1;;i++) { - dig = quorem(b,S) + '0'; - /* Do we yet have the shortest decimal string - * that will round to d? - */ - j = cmp(b, mlo); - delta = diff(S, mhi MTb); - j1 = delta->sign ? 1 : cmp(b, delta); - Bfree(delta MTb); + for (i = 1;; i++) { + dig = dtoa_quorem(b, S) + '0'; + /* Do we yet have the shortest decimal string + * that will round to d? + */ + j = dtoa_cmp(b, mlo); + delta = dtoa_diff(S, mhi MTb); + j1 = delta->sign ? 1 : dtoa_cmp(b, delta); + dtoa_bfree(delta MTb); #ifndef ROUND_BIASED - if (j1 == 0 && mode != 1 && !(word1(&u) & 1) + if (j1 == 0 && mode != 1 && !(word1(&u) & 1) #ifdef Honor_FLT_ROUNDS - && (mode <= 1 || Rounding >= 1) + && (mode <= 1 || Rounding >= 1) #endif - ) { - if (dig == '9') - goto round_9_up; - if (j > 0) - dig++; + ) { + if (dig == '9') goto round_9_up; + if (j > 0) dig++; #ifdef SET_INEXACT - else if (!b->x[0] && b->wds <= 1) - inexact = 0; + else if (!b->x[0] && b->wds <= 1) + inexact = 0; #endif - *s++ = dig; - goto ret; - } + *s++ = dig; + goto ret; + } #endif - if (j < 0 || (j == 0 && mode != 1 + if (j < 0 || (j == 0 && mode != 1 #ifndef ROUND_BIASED - && !(word1(&u) & 1) + && !(word1(&u) & 1) #endif - )) { - if (!b->x[0] && b->wds <= 1) { + )) { + if (!b->x[0] && b->wds <= 1) { #ifdef SET_INEXACT - inexact = 0; + inexact = 0; #endif - goto accept_dig; - } + goto accept_dig; + } #ifdef Honor_FLT_ROUNDS - if (mode > 1) - switch(Rounding) { - case 0: goto accept_dig; - case 2: goto keep_dig; - } + if (mode > 1) switch (Rounding) { + case 0: + goto accept_dig; + case 2: + goto keep_dig; + } #endif /*Honor_FLT_ROUNDS*/ - if (j1 > 0) { - b = lshift(b, 1 MTb); - j1 = cmp(b, S); + if (j1 > 0) { + b = dtoa_lshift(b, 1 MTb); + j1 = dtoa_cmp(b, S); #ifdef ROUND_BIASED - if (j1 >= 0 /*)*/ + if (j1 >= 0 /*)*/ #else - if ((j1 > 0 || (j1 == 0 && dig & 1)) + if ((j1 > 0 || (j1 == 0 && dig & 1)) #endif - && dig++ == '9') - goto round_9_up; - } - accept_dig: - *s++ = dig; - goto ret; - } - if (j1 > 0) { + && dig++ == '9') + goto round_9_up; + } + accept_dig: + *s++ = dig; + goto ret; + } + if (j1 > 0) { #ifdef Honor_FLT_ROUNDS - if (!Rounding && mode > 1) - goto accept_dig; + if (!Rounding && mode > 1) goto accept_dig; #endif - if (dig == '9') { /* possible if i == 1 */ - round_9_up: - *s++ = '9'; - goto roundoff; - } - *s++ = dig + 1; - goto ret; - } + if (dig == '9') { /* possible if i == 1 */ + round_9_up: + *s++ = '9'; + goto roundoff; + } + *s++ = dig + 1; + goto ret; + } #ifdef Honor_FLT_ROUNDS - keep_dig: + keep_dig: #endif - *s++ = dig; - if (i == ilim) - break; - b = multadd(b, 10, 0 MTb); - if (mlo == mhi) - mlo = mhi = multadd(mhi, 10, 0 MTb); - else { - mlo = multadd(mlo, 10, 0 MTb); - mhi = multadd(mhi, 10, 0 MTb); - } - } - } - else - for(i = 1;; i++) { - dig = quorem(b,S) + '0'; - *s++ = dig; - if (!b->x[0] && b->wds <= 1) { + *s++ = dig; + if (i == ilim) break; + b = dtoa_multadd(b, 10, 0 MTb); + if (mlo == mhi) + mlo = mhi = dtoa_multadd(mhi, 10, 0 MTb); + else { + mlo = dtoa_multadd(mlo, 10, 0 MTb); + mhi = dtoa_multadd(mhi, 10, 0 MTb); + } + } + } else + for (i = 1;; i++) { + dig = dtoa_quorem(b, S) + '0'; + *s++ = dig; + if (!b->x[0] && b->wds <= 1) { #ifdef SET_INEXACT - inexact = 0; + inexact = 0; #endif - goto ret; - } - if (i >= ilim) - break; - b = multadd(b, 10, 0 MTb); - } + goto ret; + } + if (i >= ilim) break; + b = dtoa_multadd(b, 10, 0 MTb); + } - /* Round off last digit */ + /* Round off last digit */ #ifdef Honor_FLT_ROUNDS - if (mode > 1) - switch(Rounding) { - case 0: goto ret; - case 2: goto roundoff; - } + if (mode > 1) switch (Rounding) { + case 0: + goto ret; + case 2: + goto roundoff; + } #endif - b = lshift(b, 1 MTb); - j = cmp(b, S); + b = dtoa_lshift(b, 1 MTb); + j = dtoa_cmp(b, S); #ifdef ROUND_BIASED - if (j >= 0) + if (j >= 0) #else - if (j > 0 || (j == 0 && dig & 1)) + if (j > 0 || (j == 0 && dig & 1)) #endif - { - roundoff: - while(*--s == '9') - if (s == buf) { - k++; - *s++ = '1'; - goto ret; - } - ++*s++; - } - ret: - Bfree(S MTb); - if (mhi) { - if (mlo && mlo != mhi) - Bfree(mlo MTb); - Bfree(mhi MTb); - } - retc: - while(s > buf && s[-1] == '0') - --s; - ret1: - if (b) - Bfree(b MTb); - *s = 0; - *decpt = k + 1; - if (rve) - *rve = s; + { + roundoff: + while (*--s == '9') + if (s == buf) { + k++; + *s++ = '1'; + goto ret; + } + ++*s++; + } +ret: + dtoa_bfree(S MTb); + if (mhi) { + if (mlo && mlo != mhi) dtoa_bfree(mlo MTb); + dtoa_bfree(mhi MTb); + } +retc: + while (s > buf && s[-1] == '0') --s; +ret1: + if (b) dtoa_bfree(b MTb); + *s = 0; + *decpt = k + 1; + if (rve) *rve = s; #ifdef SET_INEXACT - if (inexact) { - if (!oldinexact) { - word0(&u) = Exp_1 + (70 << Exp_shift); - word1(&u) = 0; - dval(&u) += 1.; - } - } - else if (!oldinexact) - clear_inexact(); + if (inexact) { + if (!oldinexact) { + word0(&u) = Exp_1 + (70 << Exp_shift); + word1(&u) = 0; + dval(&u) += 1.; + } + } else if (!oldinexact) + clear_inexact(); #endif - return buf; - } + return buf; +} - char * -dtoa(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve) -{ - /* Sufficient space is allocated to the return value - to hold the suppressed trailing zeros. - See dtoa_r() above for details on the other arguments. - */ +char *dtoa(double dd, int mode, int ndigits, int *decpt, int *sign, + char **rve) { + /* Sufficient space is allocated to the return value + to hold the suppressed trailing zeros. + See dtoa_r() above for details on the other arguments. + */ #ifndef MULTIPLE_THREADS - if (dtoa_result) - freedtoa(dtoa_result); + if (dtoa_result) freedtoa(dtoa_result); #endif - return dtoa_r(dd, mode, ndigits, decpt, sign, rve, 0, 0); - } + return dtoa_r(dd, mode, ndigits, decpt, sign, rve, 0, 0); +} #ifdef __cplusplus } diff --git a/third_party/dtoa/dtoa.h b/third_party/dtoa/dtoa.h index 398ba73a..15e1b3fc 100644 --- a/third_party/dtoa/dtoa.h +++ b/third_party/dtoa/dtoa.h @@ -3,20 +3,15 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -/* see also xdtoa() in //libc/x */ -double strtod(const char *s00, char **se); char *g_fmt(char *buf /*[32]*/, double x); - char *dtoa(double d, int mode, int ndigits, int *decpt, int *sign, char **rve) nodiscard; void freedtoa(char *s); char *dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve, char *buf, size_t blen); -double plan9_strtod(const char *as, char **aas); -/* #if defined(TINY) || defined(TINY_STRTOD) */ -/* #define strtod(X, Y) plan9_strtod(X, Y) */ -/* #endif */ +double strtod(const char *, char **); +double plan9_strtod(const char *, char **); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ diff --git a/third_party/xed/avx.h b/third_party/xed/avx.h new file mode 100644 index 00000000..f23e1fb3 --- /dev/null +++ b/third_party/xed/avx.h @@ -0,0 +1,43 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_XED_AVX_H_ +#define COSMOPOLITAN_THIRD_PARTY_XED_AVX_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +union XedAvxC4Payload1 { + struct { + unsigned map : 5; + unsigned b_inv : 1; + unsigned x_inv : 1; + unsigned r_inv : 1; + unsigned pad : 24; + } s; + unsigned u32; +}; + +union XedAvxC4Payload2 { + struct { + unsigned pp : 2; + unsigned l : 1; + unsigned vvv210 : 3; + unsigned v3 : 1; + unsigned w : 1; + unsigned pad : 24; + } s; + unsigned u32; +}; + +union XedAvxC5Payload { + struct { + unsigned pp : 2; + unsigned l : 1; + unsigned vvv210 : 3; + unsigned v3 : 1; + unsigned r_inv : 1; + unsigned pad : 24; + } s; + unsigned u32; +}; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_XED_AVX_H_ */ diff --git a/third_party/xed/avx512.h b/third_party/xed/avx512.h new file mode 100644 index 00000000..14385b8a --- /dev/null +++ b/third_party/xed/avx512.h @@ -0,0 +1,44 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_ +#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +union XedAvx512Payload1 { + struct { + unsigned map : 4; + unsigned rr_inv : 1; + unsigned b_inv : 1; + unsigned x_inv : 1; + unsigned r_inv : 1; + unsigned pad : 24; + } s; + unsigned u32; +}; + +union XedAvx512Payload2 { + struct { + unsigned pp : 2; + unsigned ubit : 1; + unsigned vexdest210 : 3; + unsigned vexdest3 : 1; + unsigned rexw : 1; + unsigned pad : 24; + } s; + unsigned u32; +}; + +union XedAvx512Payload3 { + struct { + unsigned mask : 3; + unsigned vexdest4p : 1; + unsigned bcrc : 1; + unsigned llrc : 2; + unsigned z : 1; + unsigned pad : 24; + } s; + unsigned u32; +}; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_ */ diff --git a/third_party/xed/x86.h b/third_party/xed/x86.h index af3c2bcb..f7a42a3f 100644 --- a/third_party/xed/x86.h +++ b/third_party/xed/x86.h @@ -313,12 +313,18 @@ struct XedChipFeatures { }; struct XedOperands { + /* data structure optimized for gcc code size */ uint8_t imm_width; uint8_t map; /* enum XedIldMap */ uint8_t error; /* enum XedError */ - uint8_t mode; - uint8_t rexw; - uint8_t osz; + uint8_t mode; /* real,legacy,long */ + uint8_t modrm; /* selects address register */ + uint8_t sib; /* scaled index base x86_64 */ + uint8_t rexw : 1; + uint8_t rexr : 1; + uint8_t rexx : 1; + uint8_t rexb : 1; + uint8_t osz; /* operand size override prefix */ uint8_t max_bytes; uint8_t nominal_opcode; uint8_t out_of_bytes; @@ -326,6 +332,7 @@ struct XedOperands { int64_t disp; uint64_t uimm0; enum XedChip chip; + uint8_t srm; uint8_t amd3dnow; uint8_t asz; uint8_t bcrc; @@ -334,16 +341,11 @@ struct XedOperands { uint8_t ild_f2; uint8_t ild_f3; uint8_t lock; - uint8_t modep5; - uint8_t modep55c; uint8_t mode_first_prefix; uint8_t prefix66; uint8_t realmode; uint8_t rex; - uint8_t rexb; - uint8_t rexr; uint8_t rexrr; - uint8_t rexx; uint8_t ubit; uint8_t vexdest3; uint8_t vexdest4; @@ -355,7 +357,6 @@ struct XedOperands { uint8_t llrc; uint8_t mod; uint8_t rep; - uint8_t sibscale; uint8_t vex_prefix; uint8_t vl; uint8_t hint; @@ -363,15 +364,11 @@ struct XedOperands { uint8_t reg; uint8_t rm; uint8_t seg_ovd; - uint8_t sibbase; - uint8_t sibindex; - uint8_t srm; uint8_t vexdest210; uint8_t vexvalid; uint8_t esrc; uint8_t ild_seg; uint8_t imm1_bytes; - uint8_t modrm_byte; uint8_t nprefixes; uint8_t nrexes; uint8_t nseg_prefixes; @@ -384,154 +381,12 @@ struct XedOperands { uint8_t uimm1; }; -struct XedInst { - uint8_t noperands; - uint8_t cpl; - uint8_t flag_complex; - uint8_t exceptions; - uint16_t flag_info_index; - uint16_t iform_enum; - uint16_t operand_base; - uint16_t attributes; -}; - -struct XedEncoderIforms { - unsigned x_MEMDISPv; - unsigned x_SIBBASE_ENCODE_SIB1; - unsigned x_VEX_MAP_ENC; - unsigned x_SIB_NT; - unsigned x_UIMM8_1; - unsigned x_SIBBASE_ENCODE; - unsigned x_VEX_ESCVL_ENC; - unsigned x_PREFIX_ENC; - unsigned x_VEXED_REX; - unsigned x_REMOVE_SEGMENT; - unsigned x_VSIB_ENC; - unsigned x_EVEX_REXB_ENC; - unsigned x_MODRM_RM_ENCODE_EA64_SIB0; - unsigned x_VEX_REXXB_ENC; - unsigned x_EVEX_REXRR_ENC; - unsigned x_AVX512_EVEX_BYTE3_ENC; - unsigned x_EVEX_REXW_VVVV_ENC; - unsigned x_VEX_REG_ENC; - unsigned x_SIMM8; - unsigned x_XOP_MAP_ENC; - unsigned x_MODRM_RM_ENCODE_EA32_SIB0; - unsigned x_UIMM8; - unsigned x_MODRM_RM_ENCODE_EA16_SIB0; - unsigned x_XOP_REXXB_ENC; - unsigned x_EVEX_MAP_ENC; - unsigned x_MEMDISP8; - unsigned x_MODRM_RM_ENCODE; - unsigned x_REX_PREFIX_ENC; - unsigned x_UIMM16; - unsigned x_VEX_TYPE_ENC; - unsigned x_EVEX_UPP_ENC; - unsigned x_VEX_REXR_ENC; - unsigned x_BRDISP32; - unsigned x_MEMDISP32; - unsigned x_MEMDISP16; - unsigned x_SIBINDEX_ENCODE; - unsigned x_SE_IMM8; - unsigned x_UIMM32; - unsigned x_SIMMz; - unsigned x_UIMMv; - unsigned x_EVEX_62_REXR_ENC; - unsigned x_DISP_NT; - unsigned x_MODRM_MOD_ENCODE; - unsigned x_MEMDISP; - unsigned x_VSIB_ENC_BASE; - unsigned x_BRDISP8; - unsigned x_BRDISPz; - unsigned x_EVEX_REXX_ENC; - unsigned x_XOP_TYPE_ENC; -}; - -struct XedEncoderVars { - struct XedEncoderIforms iforms; - unsigned short iform_index; - unsigned ilen; - unsigned olen; - unsigned bit_offset; -}; - struct XedDecodedInst { struct XedOperands operands; unsigned char decoded_length; uint8_t *bytes; }; -union XedAvxC4Payload1 { - struct { - unsigned map : 5; - unsigned b_inv : 1; - unsigned x_inv : 1; - unsigned r_inv : 1; - unsigned pad : 24; - } s; - unsigned u32; -}; - -union XedAvxC4Payload2 { - struct { - unsigned pp : 2; - unsigned l : 1; - unsigned vvv210 : 3; - unsigned v3 : 1; - unsigned w : 1; - unsigned pad : 24; - } s; - unsigned u32; -}; - -union XedAvxC5Payload { - struct { - unsigned pp : 2; - unsigned l : 1; - unsigned vvv210 : 3; - unsigned v3 : 1; - unsigned r_inv : 1; - unsigned pad : 24; - } s; - unsigned u32; -}; - -union XedAvx512Payload1 { - struct { - unsigned map : 4; - unsigned rr_inv : 1; - unsigned b_inv : 1; - unsigned x_inv : 1; - unsigned r_inv : 1; - unsigned pad : 24; - } s; - unsigned u32; -}; - -union XedAvx512Payload2 { - struct { - unsigned pp : 2; - unsigned ubit : 1; - unsigned vexdest210 : 3; - unsigned vexdest3 : 1; - unsigned rexw : 1; - unsigned pad : 24; - } s; - unsigned u32; -}; - -union XedAvx512Payload3 { - struct { - unsigned mask : 3; - unsigned vexdest4p : 1; - unsigned bcrc : 1; - unsigned llrc : 2; - unsigned z : 1; - unsigned pad : 24; - } s; - unsigned u32; -}; - forceinline unsigned char xed_decoded_inst_get_byte( const struct XedDecodedInst *p, long byte_index) { return p->bytes[byte_index]; @@ -575,7 +430,7 @@ forceinline struct XedDecodedInst *xed_decoded_inst_zero_set_mode( extern const uint64_t xed_chip_features[XED_CHIP_LAST][3] hidden; enum XedError xed_instruction_length_decode(struct XedDecodedInst *, - const unsigned char *, size_t); + const void *, size_t); bool xed_isa_set_is_valid_for_chip(enum XedIsaSet, enum XedChip); bool xed_test_chip_features(struct XedChipFeatures *, enum XedIsaSet); diff --git a/third_party/xed/x86ild.greg.c b/third_party/xed/x86ild.greg.c index e825c535..1be6b0b6 100644 --- a/third_party/xed/x86ild.greg.c +++ b/third_party/xed/x86ild.greg.c @@ -21,6 +21,8 @@ #include "libc/macros.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" +#include "third_party/xed/avx.h" +#include "third_party/xed/avx512.h" #include "third_party/xed/private.h" #include "third_party/xed/x86.h" @@ -377,7 +379,7 @@ privileged static void xed_set_chip_modes(struct XedDecodedInst *d, } privileged static xed_bool_t xed3_mode_64b(struct XedDecodedInst *d) { - return d->operands.mode == 2; + return d->operands.mode == XED_MODE_LONG; } privileged static void xed_set_hint(char b, struct XedDecodedInst *d) { @@ -610,10 +612,10 @@ out: d->operands.nseg_prefixes = nseg_prefixes; d->operands.nrexes = nrexes; if (rex) { - d->operands.rexw = (rex >> 3 & 1); - d->operands.rexr = (rex >> 2 & 1); - d->operands.rexx = (rex >> 1 & 1); - d->operands.rexb = (rex & 1); + d->operands.rexw = rex >> 3 & 1; + d->operands.rexr = rex >> 2 & 1; + d->operands.rexx = rex >> 1 & 1; + d->operands.rexb = rex & 1; d->operands.rex = 1; } if (d->operands.mode_first_prefix) { @@ -773,7 +775,7 @@ privileged static void xed_evex_scanner(struct XedDecodedInst *d) { d->operands.rexrr = ~evex1.s.rr_inv & 1; } d->operands.map = evex1.s.map; - d->operands.rexw = evex2.s.rexw; + d->operands.rexw = evex2.s.rexw & 1; d->operands.vexdest3 = evex2.s.vexdest3; d->operands.vexdest210 = evex2.s.vexdest210; d->operands.ubit = evex2.s.ubit; @@ -894,7 +896,7 @@ privileged static void xed_vex_c4_scanner(struct XedDecodedInst *d) { d->operands.rexr = ~c4byte1.s.r_inv & 1; d->operands.rexx = ~c4byte1.s.x_inv & 1; d->operands.rexb = (xed3_mode_64b(d) & ~c4byte1.s.b_inv) & 1; - d->operands.rexw = c4byte2.s.w; + d->operands.rexw = c4byte2.s.w & 1; d->operands.vexdest3 = c4byte2.s.v3; d->operands.vexdest210 = c4byte2.s.vvv210; d->operands.vl = c4byte2.s.l; @@ -965,7 +967,7 @@ privileged static void xed_xop_scanner(struct XedDecodedInst *d) { d->operands.rexr = ~xop_byte1.s.r_inv & 1; d->operands.rexx = ~xop_byte1.s.x_inv & 1; d->operands.rexb = (xed3_mode_64b(d) & ~xop_byte1.s.b_inv) & 1; - d->operands.rexw = xop_byte2.s.w; + d->operands.rexw = xop_byte2.s.w & 1; d->operands.vexdest3 = xop_byte2.s.v3; d->operands.vexdest210 = xop_byte2.s.vvv210; d->operands.vl = xop_byte2.s.l; @@ -1041,7 +1043,7 @@ privileged static void xed_modrm_scanner(struct XedDecodedInst *d) { length = d->decoded_length; if (length < d->operands.max_bytes) { b = xed_decoded_inst_get_byte(d, length); - d->operands.modrm_byte = b; + d->operands.modrm = b; d->operands.pos_modrm = length; d->decoded_length++; mod = xed_modrm_mod(b); @@ -1072,9 +1074,7 @@ privileged static void xed_sib_scanner(struct XedDecodedInst *d) { if (length < d->operands.max_bytes) { b = xed_decoded_inst_get_byte(d, length); d->operands.pos_sib = length; - d->operands.sibscale = xed_sib_scale(b); - d->operands.sibindex = xed_sib_index(b); - d->operands.sibbase = xed_sib_base(b); + d->operands.sib = b; d->decoded_length++; if (xed_sib_base(b) == 5) { if (d->operands.mod == 0) { @@ -1134,9 +1134,9 @@ privileged static void XED_LF_BRDISP32_BRDISP_WIDTH_CONST_l2( } privileged static void XED_LF_DISP_BUCKET_0_l1(struct XedDecodedInst *x) { - if (x->operands.mode <= 1) { + if (x->operands.mode <= XED_MODE_LEGACY) { XED_LF_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2(x); - } else if (x->operands.mode == 2) { + } else if (x->operands.mode == XED_MODE_LONG) { XED_LF_BRDISP32_BRDISP_WIDTH_CONST_l2(x); } } @@ -1232,7 +1232,7 @@ privileged static void xed_decode_instruction_length( * @see biggest code in gdb/clang/tensorflow binaries */ privileged enum XedError xed_instruction_length_decode( - struct XedDecodedInst *xedd, const uint8_t *itext, const size_t bytes) { + struct XedDecodedInst *xedd, const void *itext, size_t bytes) { xed_set_chip_modes(xedd, xedd->operands.chip); xedd->bytes = itext; xedd->operands.max_bytes = MIN(bytes, XED_MAX_INSTRUCTION_BYTES); diff --git a/third_party/xed/x86tab.S b/third_party/xed/x86tab.S index d47b1389..b70a6360 100644 --- a/third_party/xed/x86tab.S +++ b/third_party/xed/x86tab.S @@ -154,19 +154,19 @@ xed_has_disp_regular.rodata: .endobj xed_has_disp_regular.rodata xed_has_sib_table.rodata: - .byte 36,0x00 # 00─23 ∅─# - .byte 1,0x01 # 24─24 $ - .byte 7,0x00 # 25─2b %─+ - .byte 1,0x01 # 2c─2c , - .byte 7,0x00 # 2d─33 ──3 - .byte 1,0x01 # 34─34 4 - .byte 15,0x00 # 35─43 5─C - .byte 1,0x01 # 44─44 D - .byte 7,0x00 # 45─4b E─K - .byte 1,0x01 # 4c─4c L - .byte 7,0x00 # 4d─53 M─S - .byte 1,0x01 # 54─54 T - .byte 11,0x00 # 55─5f U─_ + .byte 36,FALSE # 00─23 ∅─# + .byte 1,TRUE # 24─24 $ + .byte 7,FALSE # 25─2b %─+ + .byte 1,TRUE # 2c─2c , + .byte 7,FALSE # 2d─33 ──3 + .byte 1,TRUE # 34─34 4 + .byte 15,FALSE # 35─43 5─C + .byte 1,TRUE # 44─44 D + .byte 7,FALSE # 45─4b E─K + .byte 1,TRUE # 4c─4c L + .byte 7,FALSE # 4d─53 M─S + .byte 1,TRUE # 54─54 T + .byte 11,FALSE # 55─5f U─_ .endobj xed_has_sib_table.rodata xed_disp_bits_2d.rodata: diff --git a/tool/build/lib/interner.c b/tool/build/lib/interner.c index b9e8496c..e886801b 100644 --- a/tool/build/lib/interner.c +++ b/tool/build/lib/interner.c @@ -100,7 +100,7 @@ size_t internobj(struct Interner *t, const void *data, size_t size) { item = data; hash = max(1, KnuthMultiplicativeHash32(data, size)); do { - /* it is written that triangle probe halts iff in - 1); if (it->p[i].hash == hash && it->p[i].index + size <= it->pool.n && memcmp(item, &it->pool.p[it->p[i].index], size) == 0) { diff --git a/tool/build/mkdeps.c b/tool/build/mkdeps.c index 111cf115..b92c0f19 100644 --- a/tool/build/mkdeps.c +++ b/tool/build/mkdeps.c @@ -79,7 +79,7 @@ struct Edge { }; struct Sources { - size_t i, n; /* phase 1: hashmap: popcount(n)==1 if n */ + size_t i, n; /* phase 1: hashmap: popcnt(n)==1 if n */ struct Source *p; /* phase 2: arraylist sorted by id */ }; diff --git a/tool/build/refactor.c b/tool/build/refactor.c index e47ffd96..05334102 100644 --- a/tool/build/refactor.c +++ b/tool/build/refactor.c @@ -84,6 +84,7 @@ void RefactorFile(const char *path) { char *mem, *spot = NULL, *part1, *part2; CHECK_NE(-1, (fd = open(path, O_RDONLY))); CHECK_NE(-1, fstat(fd, &st)); + len2 = 0; if ((len = st.st_size)) { CHECK_NE(MAP_FAILED, (mem = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0))); diff --git a/tool/decode/x86opinfo.c b/tool/decode/x86opinfo.c index cd74ba98..fd283edd 100644 --- a/tool/decode/x86opinfo.c +++ b/tool/decode/x86opinfo.c @@ -145,6 +145,8 @@ int main(int argc, char *argv[]) { SHOWOP(error); SHOWOP(esrc); SHOWOP(first_f2f3); + SHOWOP(modrm); + SHOWOP(sib); SHOWOP(has_modrm); SHOWOP(has_sib); SHOWOP(hint); @@ -162,9 +164,6 @@ int main(int argc, char *argv[]) { SHOWOP(mod); SHOWOP(mode); SHOWOP(mode_first_prefix); - SHOWOP(modep5); - SHOWOP(modep55c); - SHOWOP(modrm_byte); SHOWOP(nominal_opcode); SHOWOP(nprefixes); SHOWOP(nrexes); @@ -189,9 +188,6 @@ int main(int argc, char *argv[]) { SHOWOP(rexx); SHOWOP(rm); SHOWOP(seg_ovd); - SHOWOP(sibbase); - SHOWOP(sibindex); - SHOWOP(sibscale); SHOWOP(srm); SHOWOP(ubit); SHOWOP(uimm0); diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index fd54dbcf..fee00c5a 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -177,6 +177,7 @@ mode.\n\ #define CTRL(C) ((C) ^ 0100) #define ALT(C) ((033 << 010) | (C)) #define ARGZ(...) ((char *const[]){__VA_ARGS__, NULL}) +#define MOD(X, Y) ((X) - (ABS(Y)) * ((X) / ABS(Y))) #define BALLOC(B, A, N, NAME) \ ({ \ @@ -509,8 +510,8 @@ static bool TrySpeaker(const char *prog, char *const *args) { int rc; int fds[3]; fds[0] = -1; - fds[1] = STDERR_FILENO; - fds[2] = STDERR_FILENO; + fds[1] = fileno(g_logfile); + fds[2] = fileno(g_logfile); LOGF("spawning %s", prog); if ((rc = spawnve(0, fds, prog, args, environ)) != -1) { playpid_ = rc; @@ -541,8 +542,8 @@ static bool OpenSpeaker(void) { if (!once) { once = true; i = 0; - if (sox_) tryspeakerfns_[i++] = TrySox; if (ffplay_) tryspeakerfns_[i++] = TryFfplay; + if (sox_) tryspeakerfns_[i++] = TrySox; } snprintf(fifopath_, sizeof(fifopath_), "%s%s.%d.%d.wav", kTmpPath, program_invocation_short_name, getpid(), count);