# RV32I With Long Double Support ## Why Doing This The default riscv-none-elf-gcc-xpack build of Newlib does not enable long double support. I want to enable long double support for RV32I. The [ieee754.c](https://github.com/sysprog21/rv32emu/blob/master/tests/ieee754.c) file shipped with RV32EMU was originally written by [Dr. Vincent Lefèvre](https://www.vinc17.net/research/index.en.html) . I found a FIXME and tried to fix it: ```cpp #if 0 /* FIXME: make it work */ printf("LDBL_MAX = %La%s\n", lm, ERRSTR(lm != ldbl_max)); #endif ``` ## How to Do 1. Rebuild Newlib with long double support 2. Compare RV32I long double support before and after 3. Compare calculation results between PC and RV32I emulator 4. Verify the results (Draft) ## Re-Build the Newlib ### Build Newlib Only ```bash riscv-none-elf-gcc -v Using built-in specs. COLLECT_GCC=riscv-none-elf-gcc COLLECT_LTO_WRAPPER=/home/eastwillow/.local/xPacks/@xpack-dev-tools/riscv-none-elf-gcc/14.2.0-3.1/.content/bin/../libexec/gcc/riscv-none-elf/14.2.0/lto-wrapper ... ``` The newlib used in riscv-none-elf-gcc is version 14.2.0-3.1 https://xpack-dev-tools.github.io/riscv-none-elf-gcc-xpack/blog/2024/12/06/riscv-none-elf-gcc-v14-2-0-3-released/ Newlib version: 4.4.0 Download from https://sourceware.org/pub/newlib/ ``` wget ftp://sourceware.org/pub/newlib/newlib-4.4.0.20231231.tar.gz tar xzf newlib-4.4.0.20231231.tar.gz cd newlib-4.4.0.20231231 ``` #### Configure: ```shell ../configure \ --target=riscv-none-elf \ --prefix=$HOME/opt/riscv-newlib-debug \ --enable-newlib-io-long-long \ --enable-newlib-io-c99-formats \ --enable-newlib-register-fini \ --enable-newlib-retargetable-locking \ --enable-newlib-mb \ --enable-newlib-reent-check-verify \ --enable-newlib-io-long-double ``` #### Build: ```shell make CC_FOR_TARGET=riscv-none-elf-gcc CFLAGS="-g -O0" all ``` **Newlib configure reference** From xPack Dev Tools [github action](https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/actions/runs/18744298753/job/53467796369) See also: * [newlib-cross.sh]( https://github.com/xpack-dev-tools/xbb-helper-xpack/blob/xpack/dependencies/newlib-cross.sh) * [archlinux pkg-build](https://gitlab.archlinux.org/archlinux/packaging/packages/riscv32-elf-newlib/-/blob/main/PKGBUILD) ### Build the Entire riscv-none-elf-gcc-xpack Clone and add --enable-newlib-io-long-double and debug flags: ```shell riscv-none-elf-gcc-xpack.git/build-assets/xpacks/@xpack-dev-tools/xbb-helper/dependencies/newlib-cross.sh ``` Then build: https://xpack-dev-tools.github.io/riscv-none-elf-gcc-xpack/docs/developer/ ```shell xpm run install -C ~/Work/xpack-dev-tools/riscv-none-elf-gcc-xpack.git/build-assets && \ xpm run docker-prepare --config linux-x64 -C ~/Work/xpack-dev-tools/riscv-none-elf-gcc-xpack.git/build-assets xpm run build-development-debug --config linux-x64 -C ~/Work/xpack-dev-tools/riscv-none-elf-gcc-xpack.git/build-assets ``` Manual Installation globally (now version is `15.2.0-1`) ```bash mkdir -p ~/.local/xPacks/riscv-none-elf-gcc cd ~/.local/xPacks/riscv-none-elf-gcc tar xvf ~/Work/xpack-dev-tools/riscv-none-elf-gcc-xpack.git/build-assets/build/linux-x64/deploy/xpack-riscv-none-elf-gcc-15.2.0-1-linux-x64.tar.gz ``` PATH setup in ~/.bashrc ``` export PATH=$HOME/.local/xPacks/riscv-none-elf-gcc/xpack-riscv-none-elf-gcc-15.2.0-1/bin:$PATH ``` ## Long double has multiple implementation variants. In glibc on x86_64, the default `LDBL_MANT_DIG` is 64. When Newlib enables long double on RV32I, `LDBL_MANT_DIG` becomes 113. According to the [GNU manual](https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html ), you need to add the flag `-mlong-double-128` ## PC Build Command with 128-bit Long Double ```shell gcc -Wall -O2 -std=c99 -o tests/ieee754_pc tests/ieee754.c -lm -mlong-double-128 && \ tests/ieee754_pc > pc_output.txt ``` ## RV32I Command (Using Custom-Built Newlib) ```shell riscv-none-elf-gcc -I$HOME/opt/riscv-newlib-debug/riscv-none-elf/include -L$HOME/opt/riscv-newlib-debug/riscv-none-elf/lib -Wall -O2 -std=c99 -march=rv32if -mabi=ilp32 -o tests/ieee754_after tests/ieee754.c -lm && \ build/rv32emu tests/ieee754_after > rv32_after.txt ``` ## RV32I Command (Using Full riscv-none-elf-gcc-xpack Build) ```shell riscv-none-elf-gcc -Wall -O2 -std=c99 -march=rv32if -mabi=ilp32 -o tests/ieee754_after tests/ieee754.c -lm && \ build/rv32emu tests/ieee754_after > rv32_after.txt ``` ## RV32I Supported Long Double Before & After Diff ```shell git diff --no-index rv32_before.txt rv32_after.txt > rv32_before_after.diff ``` ```diff diff --git a/rv32_before.txt b/rv32_after.txt index ec918d1..89ee1d5 100644 --- a/rv32_before.txt +++ b/rv32_after.txt @@ -1,6 +1,6 @@ -23:26:25 INFO  src/riscv.c:552: Log level: TRACE -23:26:25 INFO  src/riscv.c:565: tests/ieee754_before ELF loaded -23:26:25 INFO  src/main.c:315: RISC-V emulator is created and ready to run +23:58:51 INFO  src/riscv.c:552: Log level: TRACE +23:58:51 INFO  src/riscv.c:565: tests/ieee754_after ELF loaded +23:58:51 INFO  src/main.c:315: RISC-V emulator is created and ready to run FLT_RADIX = 2 FLT_MANT_DIG = 24 DBL_MANT_DIG = 53 @@ -20,11 +20,11 @@ LDBL_EPSILON = 1.92593e-34 = 0x1p-112 FLT_MIN = 1.17549e-38 = 0x1p-126 DBL_MIN = 2.22507e-308 = 0x1p-1022 -LDBL_MIN = 0 = 0x0p+0 +LDBL_MIN = 3.3621e-4932 = 0x1p-16382 FLT_MAX = 3.40282e+38 = 0x1.fffffep+127 DBL_MAX = 1.79769e+308 = 0x1.fffffffffffffp+1023 -LDBL_MAX = inf = inf +LDBL_MAX = 1.18973e+4932 = 0x1.ffffffffffffffffffffffffffffp+16383 sizeof(float) = 4 sizeof(double) = 8 @@ -81,11 +81,11 @@ Constant expression 1 - DBL_MIN = 1 Variable expression 1 - DBL_MIN = 1 1/3 in float : 0x1.555556p-2 1/3 in double : 0x1.5555555555555p-2 -1/3 in long double : 0x1.5555555555555p-2 +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = inf +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 LDBL_EPSILON = 0x1p-112 @@ -242,11 +242,11 @@ Constant expression 1 - DBL_MIN = 1 Variable expression 1 - DBL_MIN = 1 1/3 in float : 0x1.555556p-2 1/3 in double : 0x1.5555555555555p-2 -1/3 in long double : 0x1.5555555555555p-2 +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = inf +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 LDBL_EPSILON = 0x1p-112 @@ -403,11 +403,11 @@ Constant expression 1 - DBL_MIN = 1 Variable expression 1 - DBL_MIN = 1 1/3 in float : 0x1.555556p-2 1/3 in double : 0x1.5555555555555p-2 -1/3 in long double : 0x1.5555555555555p-2 +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = inf +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 LDBL_EPSILON = 0x1p-112 @@ -564,11 +564,11 @@ Constant expression 1 - DBL_MIN = 1 Variable expression 1 - DBL_MIN = 1 1/3 in float : 0x1.555556p-2 1/3 in double : 0x1.5555555555555p-2 -1/3 in long double : 0x1.5555555555555p-2 +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = inf +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 LDBL_EPSILON = 0x1p-112 @@ -693,4 +693,4 @@ pow(-2, 1) = -2 pow(-2, -1) = -0.5 pow(-2, 2) = 4 pow(-2, -2) = 0.25 -23:26:25 INFO  src/main.c:338: RISC-V emulator is destroyed +23:58:51 INFO  src/main.c:338: RISC-V emulator is destroyed ``` ## PC Compare with RV32I Result (Draft) ```shell git diff --no-index pc_output.txt rv32_after.txt > pc_rv32_after.diff ``` ```shell gcc -v gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) ``` ```diff diff --git a/pc_output.txt b/rv32_after.txt index 67d186e..617e449 100644 --- a/pc_output.txt +++ b/rv32_after.txt @@ -1,3 +1,6 @@ +23:54:32 INFO  src/riscv.c:552: Log level: TRACE +23:54:32 INFO  src/riscv.c:565: tests/ieee754_after ELF loaded +23:54:32 INFO  src/main.c:315: RISC-V emulator is created and ready to run FLT_RADIX = 2 FLT_MANT_DIG = 24 DBL_MANT_DIG = 53 @@ -13,24 +16,20 @@ LDBL_MAX_EXP = 16384 FLT_EPSILON = 1.19209e-07 = 0x1p-23 DBL_EPSILON = 2.22045e-16 = 0x1p-52 -LDBL_EPSILON = nan = 0x3.38p-16385 +LDBL_EPSILON = 1.92593e-34 = 0x1p-112 FLT_MIN = 1.17549e-38 = 0x1p-126 DBL_MIN = 2.22507e-308 = 0x1p-1022 -LDBL_MIN = nan = 0x3.38p-16385 +LDBL_MIN = 3.3621e-4932 = 0x1p-16382 FLT_MAX = 3.40282e+38 = 0x1.fffffep+127 DBL_MAX = 1.79769e+308 = 0x1.fffffffffffffp+1023 -LDBL_MAX = nan = 0x3.38p-16385 +LDBL_MAX = 1.18973e+4932 = 0x1.ffffffffffffffffffffffffffffp+16383 sizeof(float) = 4 sizeof(double) = 8 sizeof(long double) = 16 -__STDC_IEC_559__ defined: -The implementation shall conform to the IEEE-754 standard. -FLT_EVAL_METHOD is 0 (see ISO/IEC 9899, 5.2.4.2.2#8). - x + y, with x = 9007199254740994.0 and y = 1.0 - 1/65536.0 (type double). The IEEE-754 result is 9007199254740994 with double precision. The IEEE-754 result is 9007199254740996 with extended precision. @@ -82,14 +81,14 @@ Constant expression 1 - DBL_MIN = 1 Variable expression 1 - DBL_MIN = 1 1/3 in float : 0x1.555556p-2 1/3 in double : 0x1.5555555555555p-2 -1/3 in long double : nan +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = nan +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 -LDBL_EPSILON = nan +LDBL_EPSILON = 0x1p-112 pow(nan, nan) = nan pow(nan, inf) = nan pow(nan, -inf) = nan @@ -161,8 +160,8 @@ pow(-0.5, inf) = 0 pow(-0.5, -inf) = inf pow(-0.5, 0) = 1 pow(-0.5, -0) = 1 -pow(-0.5, 0.5) = -nan -pow(-0.5, -0.5) = -nan +pow(-0.5, 0.5) = nan +pow(-0.5, -0.5) = nan pow(-0.5, 1) = -0.5 pow(-0.5, -1) = -2 pow(-0.5, 2) = 0.25 @@ -183,8 +182,8 @@ pow(-1, inf) = 1 pow(-1, -inf) = 1 pow(-1, 0) = 1 pow(-1, -0) = 1 -pow(-1, 0.5) = -nan -pow(-1, -0.5) = -nan +pow(-1, 0.5) = nan +pow(-1, -0.5) = nan pow(-1, 1) = -1 pow(-1, -1) = -1 pow(-1, 2) = 1 @@ -205,15 +204,15 @@ pow(-2, inf) = inf pow(-2, -inf) = 0 pow(-2, 0) = 1 pow(-2, -0) = 1 -pow(-2, 0.5) = -nan -pow(-2, -0.5) = -nan +pow(-2, 0.5) = nan +pow(-2, -0.5) = nan pow(-2, 1) = -2 pow(-2, -1) = -0.5 pow(-2, 2) = 4 pow(-2, -2) = 0.25 Rounding toward 0 --------> toward 0 (to -oo / to nearest) +-------> to nearest (to nearest / to nearest) (double) 0 = 0 Signed zero tests (x is 0.0 and y is -0.0): Test 1.0 / x != 1.0 / y returns 1 (should be 1). @@ -240,17 +239,17 @@ Signed zero tests (x is 0.0 and y is -0.0): Constant expression 1 + DBL_MIN = 1 Variable expression 1 + DBL_MIN = 1 Constant expression 1 - DBL_MIN = 1 -Variable expression 1 - DBL_MIN = 0.99999999999999988897 -1/3 in float : 0x1.555554p-2 +Variable expression 1 - DBL_MIN = 1 +1/3 in float : 0x1.555556p-2 1/3 in double : 0x1.5555555555555p-2 -1/3 in long double : nan +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = nan +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 -LDBL_EPSILON = nan +LDBL_EPSILON = 0x1p-112 pow(nan, nan) = nan pow(nan, inf) = nan pow(nan, -inf) = nan @@ -311,23 +310,23 @@ pow(0.5, inf) = 0 pow(0.5, -inf) = inf pow(0.5, 0) = 1 pow(0.5, -0) = 1 -pow(0.5, 0.5) = 0.707106 +pow(0.5, 0.5) = 0.707107 pow(0.5, -0.5) = 1.41421 pow(0.5, 1) = 0.5 -pow(0.5, -1) = 1.99999 +pow(0.5, -1) = 2 pow(0.5, 2) = 0.25 -pow(0.5, -2) = 3.99999 +pow(0.5, -2) = 4 pow(-0.5, nan) = nan pow(-0.5, inf) = 0 pow(-0.5, -inf) = inf pow(-0.5, 0) = 1 pow(-0.5, -0) = 1 -pow(-0.5, 0.5) = -nan -pow(-0.5, -0.5) = -nan +pow(-0.5, 0.5) = nan +pow(-0.5, -0.5) = nan pow(-0.5, 1) = -0.5 -pow(-0.5, -1) = -1.99999 +pow(-0.5, -1) = -2 pow(-0.5, 2) = 0.25 -pow(-0.5, -2) = 3.99999 +pow(-0.5, -2) = 4 pow(1, nan) = 1 pow(1, inf) = 1 pow(1, -inf) = 1 @@ -344,8 +343,8 @@ pow(-1, inf) = 1 pow(-1, -inf) = 1 pow(-1, 0) = 1 pow(-1, -0) = 1 -pow(-1, 0.5) = -nan -pow(-1, -0.5) = -nan +pow(-1, 0.5) = nan +pow(-1, -0.5) = nan pow(-1, 1) = -1 pow(-1, -1) = -1 pow(-1, 2) = 1 @@ -356,25 +355,25 @@ pow(2, -inf) = 0 pow(2, 0) = 1 pow(2, -0) = 1 pow(2, 0.5) = 1.41421 -pow(2, -0.5) = 0.707106 -pow(2, 1) = 1.99999 +pow(2, -0.5) = 0.707107 +pow(2, 1) = 2 pow(2, -1) = 0.5 -pow(2, 2) = 3.99999 +pow(2, 2) = 4 pow(2, -2) = 0.25 pow(-2, nan) = nan pow(-2, inf) = inf pow(-2, -inf) = 0 pow(-2, 0) = 1 pow(-2, -0) = 1 -pow(-2, 0.5) = -nan -pow(-2, -0.5) = -nan -pow(-2, 1) = -1.99999 +pow(-2, 0.5) = nan +pow(-2, -0.5) = nan +pow(-2, 1) = -2 pow(-2, -1) = -0.5 -pow(-2, 2) = 3.99999 +pow(-2, 2) = 4 pow(-2, -2) = 0.25 Rounding to -oo --------> to -oo (to -oo / to nearest) +-------> to nearest (to nearest / to nearest) (double) 0 = 0 Signed zero tests (x is 0.0 and y is -0.0): Test 1.0 / x != 1.0 / y returns 1 (should be 1). @@ -383,16 +382,16 @@ Signed zero tests (x is 0.0 and y is -0.0): Test 1.0 / x != 1.0 / -x returns 1 (should be 1). Test 1.0 / x == 1.0 / -y returns 1 (should be 1). 0 + 0 = 0 -0 - 0 = -0 -0 + -0 = -0 +0 - 0 = 0 +0 + -0 = 0 0 - -0 = 0 --0 + 0 = -0 +-0 + 0 = 0 -0 - 0 = -0 -0 + -0 = -0 --0 - -0 = -0 +-0 - -0 = 0 1 + 1 = 2 -1 - 1 = -0 -1 + -1 = -0 +1 - 1 = 0 +1 + -1 = 0 1 - -1 = 2 0 * 0 = 0 0 * -0 = -0 @@ -401,17 +400,17 @@ Signed zero tests (x is 0.0 and y is -0.0): Constant expression 1 + DBL_MIN = 1 Variable expression 1 + DBL_MIN = 1 Constant expression 1 - DBL_MIN = 1 -Variable expression 1 - DBL_MIN = 0.99999999999999988897 -1/3 in float : 0x1.555554p-2 +Variable expression 1 - DBL_MIN = 1 +1/3 in float : 0x1.555556p-2 1/3 in double : 0x1.5555555555555p-2 -1/3 in long double : nan +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = nan +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 -LDBL_EPSILON = nan +LDBL_EPSILON = 0x1p-112 pow(nan, nan) = nan pow(nan, inf) = nan pow(nan, -inf) = nan @@ -472,23 +471,23 @@ pow(0.5, inf) = 0 pow(0.5, -inf) = inf pow(0.5, 0) = 1 pow(0.5, -0) = 1 -pow(0.5, 0.5) = 0.707106 +pow(0.5, 0.5) = 0.707107 pow(0.5, -0.5) = 1.41421 -pow(0.5, 1) = 0.499999 -pow(0.5, -1) = 1.99999 -pow(0.5, 2) = 0.249999 -pow(0.5, -2) = 3.99999 +pow(0.5, 1) = 0.5 +pow(0.5, -1) = 2 +pow(0.5, 2) = 0.25 +pow(0.5, -2) = 4 pow(-0.5, nan) = nan pow(-0.5, inf) = 0 pow(-0.5, -inf) = inf pow(-0.5, 0) = 1 pow(-0.5, -0) = 1 -pow(-0.5, 0.5) = -nan -pow(-0.5, -0.5) = -nan +pow(-0.5, 0.5) = nan +pow(-0.5, -0.5) = nan pow(-0.5, 1) = -0.5 pow(-0.5, -1) = -2 -pow(-0.5, 2) = 0.249999 -pow(-0.5, -2) = 3.99999 +pow(-0.5, 2) = 0.25 +pow(-0.5, -2) = 4 pow(1, nan) = 1 pow(1, inf) = 1 pow(1, -inf) = 1 @@ -505,8 +504,8 @@ pow(-1, inf) = 1 pow(-1, -inf) = 1 pow(-1, 0) = 1 pow(-1, -0) = 1 -pow(-1, 0.5) = -nan -pow(-1, -0.5) = -nan +pow(-1, 0.5) = nan +pow(-1, -0.5) = nan pow(-1, 1) = -1 pow(-1, -1) = -1 pow(-1, 2) = 1 @@ -517,25 +516,25 @@ pow(2, -inf) = 0 pow(2, 0) = 1 pow(2, -0) = 1 pow(2, 0.5) = 1.41421 -pow(2, -0.5) = 0.707106 -pow(2, 1) = 1.99999 +pow(2, -0.5) = 0.707107 +pow(2, 1) = 2 pow(2, -1) = 0.5 -pow(2, 2) = 3.99999 +pow(2, 2) = 4 pow(2, -2) = 0.25 pow(-2, nan) = nan pow(-2, inf) = inf pow(-2, -inf) = 0 pow(-2, 0) = 1 pow(-2, -0) = 1 -pow(-2, 0.5) = -nan -pow(-2, -0.5) = -nan +pow(-2, 0.5) = nan +pow(-2, -0.5) = nan pow(-2, 1) = -2 -pow(-2, -1) = -0.500001 -pow(-2, 2) = 3.99999 +pow(-2, -1) = -0.5 +pow(-2, 2) = 4 pow(-2, -2) = 0.25 Rounding to +oo --------> to +oo (to nearest / to nearest) +-------> to nearest (to nearest / to nearest) (double) 0 = 0 Signed zero tests (x is 0.0 and y is -0.0): Test 1.0 / x != 1.0 / y returns 1 (should be 1). @@ -560,19 +559,19 @@ Signed zero tests (x is 0.0 and y is -0.0): -0 * 0 = -0 -0 * -0 = 0 Constant expression 1 + DBL_MIN = 1 -Variable expression 1 + DBL_MIN = 1.0000000000000002221 +Variable expression 1 + DBL_MIN = 1 Constant expression 1 - DBL_MIN = 1 Variable expression 1 - DBL_MIN = 1 1/3 in float : 0x1.555556p-2 -1/3 in double : 0x1.5555555555556p-2 -1/3 in long double : nan +1/3 in double : 0x1.5555555555555p-2 +1/3 in long double : 0x1.5555555555555555555555555555p-2 Dec 1.1 = 0x1.199999999999ap+0 FLT_MAX = 0x1.fffffep+127 DBL_MAX = 0x1.fffffffffffffp+1023 -LDBL_MAX = nan +LDBL_MAX = 0x1.ffffffffffffffffffffffffffffp+16383 FLT_EPSILON = 0x1p-23 DBL_EPSILON = 0x1p-52 -LDBL_EPSILON = nan +LDBL_EPSILON = 0x1p-112 pow(nan, nan) = nan pow(nan, inf) = nan pow(nan, -inf) = nan @@ -634,7 +633,7 @@ pow(0.5, -inf) = inf pow(0.5, 0) = 1 pow(0.5, -0) = 1 pow(0.5, 0.5) = 0.707107 -pow(0.5, -0.5) = 1.41422 +pow(0.5, -0.5) = 1.41421 pow(0.5, 1) = 0.5 pow(0.5, -1) = 2 pow(0.5, 2) = 0.25 @@ -644,10 +643,10 @@ pow(-0.5, inf) = 0 pow(-0.5, -inf) = inf pow(-0.5, 0) = 1 pow(-0.5, -0) = 1 -pow(-0.5, 0.5) = -nan -pow(-0.5, -0.5) = -nan -pow(-0.5, 1) = -0.499999 -pow(-0.5, -1) = -1.99999 +pow(-0.5, 0.5) = nan +pow(-0.5, -0.5) = nan +pow(-0.5, 1) = -0.5 +pow(-0.5, -1) = -2 pow(-0.5, 2) = 0.25 pow(-0.5, -2) = 4 pow(1, nan) = 1 @@ -666,8 +665,8 @@ pow(-1, inf) = 1 pow(-1, -inf) = 1 pow(-1, 0) = 1 pow(-1, -0) = 1 -pow(-1, 0.5) = -nan -pow(-1, -0.5) = -nan +pow(-1, 0.5) = nan +pow(-1, -0.5) = nan pow(-1, 1) = -1 pow(-1, -1) = -1 pow(-1, 2) = 1 @@ -677,20 +676,21 @@ pow(2, inf) = inf pow(2, -inf) = 0 pow(2, 0) = 1 pow(2, -0) = 1 -pow(2, 0.5) = 1.41422 +pow(2, 0.5) = 1.41421 pow(2, -0.5) = 0.707107 pow(2, 1) = 2 -pow(2, -1) = 0.500001 +pow(2, -1) = 0.5 pow(2, 2) = 4 -pow(2, -2) = 0.250001 +pow(2, -2) = 0.25 pow(-2, nan) = nan pow(-2, inf) = inf pow(-2, -inf) = 0 pow(-2, 0) = 1 pow(-2, -0) = 1 -pow(-2, 0.5) = -nan -pow(-2, -0.5) = -nan -pow(-2, 1) = -1.99999 +pow(-2, 0.5) = nan +pow(-2, -0.5) = nan +pow(-2, 1) = -2 pow(-2, -1) = -0.5 pow(-2, 2) = 4 -pow(-2, -2) = 0.250001 +pow(-2, -2) = 0.25 +23:54:32 INFO  src/main.c:338: RISC-V emulator is destroyed ``` ## Reference https://zh.wikipedia.org/zh-tw/IEEE_754 https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html