Skip to content

On AArch64 sin function causes floating point exception different from musl #24184

Closed
@papparapa

Description

@papparapa

Zig Version

0.15.0-dev.828+3ce8d19f7

Steps to Reproduce and Observed Behavior

Related to #2879

I tested ziglibc's sin function with zig-libc-test.

$ git clone https://github.com/rpkak/zig-libc-test
$ cd zig-libc-test

Since zig-libc-test currently specifies the sin function test as unstable, probably because of the problem described below, I built it with unstable tests enabled.

$ zig build -Dtarget=aarch64-linux-musl -Dunstable

Then I ran the sin function test.
Since it was built targeting AArch64, it would need QEMU to run on x86_64.

$ ./zig-out/bin/sin
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:41: bad fp exception: RN sin(0x1p-1022)=0x1p-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:42: bad fp exception: RN sin(-0x1p-1022)=-0x1p-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:91: bad fp exception: RN sin(0x1.0000000000001p-1022)=0x1.0000000000001p-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:92: bad fp exception: RN sin(0x1.0000000000002p-1022)=0x1.0000000000002p-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:93: bad fp exception: RN sin(0x1.ffffffffffffbp-1022)=0x1.ffffffffffffbp-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:94: bad fp exception: RN sin(0x1p-1021)=0x1p-1021, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:95: bad fp exception: RN sin(0x1.0000000000003p-1021)=0x1.0000000000003p-1021, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:96: bad fp exception: RN sin(0x1p-1020)=0x1p-1020, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:99: bad fp exception: RN sin(-0x1.0000000000001p-1022)=-0x1.0000000000001p-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:100: bad fp exception: RN sin(-0x1.0000000000002p-1022)=-0x1.0000000000002p-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:101: bad fp exception: RN sin(-0x1.ffffffffffffbp-1022)=-0x1.ffffffffffffbp-1022, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:102: bad fp exception: RN sin(-0x1p-1021)=-0x1p-1021, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:103: bad fp exception: RN sin(-0x1.0000000000003p-1021)=-0x1.0000000000003p-1021, want INEXACT got INEXACT|UNDERFLOW
/root/.cache/zig/p/N-V-__8AAPikfwDIfC1CVrl4uGQ-E2YaF3RPOFgdzAobXKzg/src/math/ucb/sin.h:104: bad fp exception: RN sin(-0x1p-1020)=-0x1p-1020, want INEXACT got INEXACT|UNDERFLOW

This output indicates that some arguments caused floating-point exceptions that differ from expectations.
I tested musl sin with libc-test just to be sure, but there was no difference from expectations.
This means that both musl and ziglibc raise floating point exceptions for these arguments, but the types of these exceptions are different between musl and ziglibc in some cases.
I have also tried on RV64 and x86_64, but this did not happen on those architectures.

Expected Behavior

If the expected exceptions occur, the zig-libc-test executable will output nothing.

$ ./zig-out/bin/sin
$

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcompiler-rt

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions