zig icon indicating copy to clipboard operation
zig copied to clipboard

libc: replace musl's trigonometric functions with compiler_rt's

Open papparapa opened this issue 5 months ago • 3 comments

Part of #2879. According to the instruction, this PR removes some musl files, including the following functions:

  • sin
  • sinf
  • cos
  • cosf
  • sincos
  • sincosf
  • tan
  • tanf

I confirmed that running zig build test-modules and zig-libc-test raised no errors during the trigonometric function tests. zig-libc-test revealed some discrepancies between the results of long double trigonometric functions in compiler_rt and musl. Therefore, this PR is restricted to float and double functions.

papparapa avatar May 31 '25 06:05 papparapa

It seems like we also have

  • cosf
  • sincos (includes sincosl?)
  • sincosf
  • sinf
  • tanf

in lib/libc/mingw.

alexrp avatar May 31 '25 20:05 alexrp

When deleting musl files, I was able to run the deletion after confirming with zig-libc-test that the function behavior did not change. However, I am not sure what policy I can use to delete MinGW files. The behavior of compiler_rt's sin function and musl's sin function are consistent, but MinGW's sin function may not be. Do I need to make sure that the behavior of compiler_rt's sin function and MinGW's sin function match? Or, even if the behavior does not match, can we assume that musl's sin function (compiler_rt's sin function) behavior is more appropriate and remove MinGW's sin function?

papparapa avatar Jun 01 '25 01:06 papparapa

Do I need to make sure that the behavior of compiler_rt's sin function and MinGW's sin function match?

I don't think so. musl tends to be pretty good about math functions, so until we have evidence to the contrary, let's assume that it's a good baseline for math functions for all static libcs.

alexrp avatar Jun 01 '25 02:06 alexrp

Thanks, I deleted the MinGW files with relief. (71ff3830) In lib/libc/mingw/math/arm/sincos.S and lib/libc/mingw/math/arm64/sincos.S, I removed only the sincos symbol. It will not be too late to remove MinGW's sincosl at the same time as musl.

papparapa avatar Jun 01 '25 11:06 papparapa

Nice, thank you

andrewrk avatar Jun 03 '25 06:06 andrewrk

Sorry @alexrp, I didn't notice you had assigned yourself or I would have left it in your hands.

andrewrk avatar Jun 03 '25 16:06 andrewrk

No worries, I'm not calling dibs or anything. :slightly_smiling_face:

alexrp avatar Jun 03 '25 17:06 alexrp