Skip to content

Commit

Permalink
atan and cbrt, updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolm committed Jan 26, 2024
1 parent 535015e commit 6f7f4fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ Here's the benchmark results on my old Intel Core i7 from 2018 (time for 32 bill
* mm256_acos_ps : 24650ms
* mm256_exp_ps : 24387ms

Use __MATH_INTRINSINCS_FAST__ if needed.
Use \_\_MATH_INTRINSINCS_FAST\_\_ if needed.

## why AVX2 ?

On multiple functions this library use a float as an int to have access to the mantissa and the exponent part. While it's doable with AVX1 using SSE4.2, I don't see the point of not using AVX2 which have been on intel CPU since 2013.

## does it handle all float cases (+inf, -inf, NAN) as the C math lib?

No, infinity, NAN are not supported as input.
Yes, all functions (even the fast ones) are compliant to +inf, -inf, NAN and other special cases (for example log(-4) == NAN). All based on the doc found here https://en.cppreference.com/w/

## what's tested?

The unit tests cover precision and special cases (inf, nan, ...). At the moment, the Neon version is not ran on GitHub but rather manually on my M1 Pro machine as I didn't had time to setup the emulator properly.
26 changes: 26 additions & 0 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define _CRT_SECURE_NO_WARNINGS
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down Expand Up @@ -255,6 +257,18 @@ SUITE(infinity_nan_compliance)
RUN_TESTp(nan_expected, -2.f, mm256_acos_ps);
RUN_TESTp(value_expected, 1.f, 0.f, mm256_acos_ps);

// atan
RUN_TESTp(nan_expected, not_a_number, mm256_atan_ps);
RUN_TESTp(value_expected, 0.f, 0.f, mm256_atan_ps);
RUN_TESTp(value_expected, -0.f, -0.f, mm256_atan_ps);
RUN_TESTp(value_expected, positive_inf, (float)M_PI_2, mm256_atan_ps);
RUN_TESTp(value_expected, negative_inf, (float)-M_PI_2, mm256_atan_ps);

// cbrt
RUN_TESTp(nan_expected, not_a_number, mm256_cbrt_ps);
RUN_TESTp(value_expected, 0.f, 0.f, mm256_cbrt_ps);
RUN_TESTp(value_expected, -0.f, -0.f, mm256_cbrt_ps);

#else
RUN_TESTp(nan_expected, -1.f, vlogq_f32);
RUN_TESTp(nan_expected, not_a_number, vlogq_f32);
Expand Down Expand Up @@ -308,6 +322,18 @@ SUITE(infinity_nan_compliance)
RUN_TESTp(nan_expected, 2.f, vacosq_f32);
RUN_TESTp(nan_expected, -2.f, vacosq_f32);
RUN_TESTp(value_expected, 1.f, 0.f, vacosq_f32);

// atan
RUN_TESTp(nan_expected, not_a_number, vatanq_f32);
RUN_TESTp(value_expected, 0.f, 0.f, vatanq_f32);
RUN_TESTp(value_expected, -0.f, -0.f, vatanq_f32);
RUN_TESTp(value_expected, positive_inf, (float)M_PI_2, vatanq_f32);
RUN_TESTp(value_expected, negative_inf, (float)-M_PI_2, vatanq_f32);

// cbrt
RUN_TESTp(nan_expected, not_a_number, vcbrtq_f32);
RUN_TESTp(value_expected, 0.f, 0.f, vcbrtq_f32);
RUN_TESTp(value_expected, -0.f, -0.f, vcbrtq_f32);
#endif
}

Expand Down

0 comments on commit 6f7f4fa

Please sign in to comment.