Last active
March 15, 2026 23:33
-
-
Save nico/917eac60ecd3c087e0a0170459148fd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <AK/Math.h> | |
| #include <float.h> | |
| #include <stdio.h> | |
| float serenity_sin(float f) | |
| { | |
| return AK::sin(f); | |
| } | |
| #if 1 | |
| #include <math.h> | |
| float reference_sin(float f) | |
| { | |
| return ::sin(f); | |
| } | |
| #else | |
| #include "shared/math.h" | |
| // Use `-I ~/src/llvm-project/libc`. | |
| // Known to be exact for floats: https://members.loria.fr/PZimmermann/papers/accuracy.pdf | |
| float reference_sin(float f) | |
| { | |
| return LIBC_NAMESPACE::shared::sin(f); | |
| } | |
| #endif | |
| int main() | |
| { | |
| float f = 0; | |
| float max_error = 0, max_arg = 0;; | |
| while (f < 2 * M_PI) { | |
| float serenity_result = serenity_sin(f); | |
| float reference_result = reference_sin(f); | |
| float abs_error = fabs(serenity_result - reference_result); | |
| if (abs_error > max_error) { | |
| max_error = abs_error; | |
| max_arg = f; | |
| } | |
| f = nextafterf(f, INFINITY); | |
| } | |
| printf("max error: %f\n", max_error); | |
| printf("AK::sin(%f) = %f\n", max_arg, serenity_sin(max_arg)); | |
| printf("ref sin(%f) = %f\n", max_arg, reference_sin(max_arg)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment