# HG changeset patch # User Mike Becker # Date 1752406551 -7200 # Node ID 030fa72d516a3c5fdf0543406c1f75179e624d71 # Parent cf0579d3bbc49b85cf9b8f769a6e04f52d84db58 add functions for sin() and cos() with increased precision when the return value is supposed to be zero diff -r cf0579d3bbc4 -r 030fa72d516a src/ascension/datatypes.h --- a/src/ascension/datatypes.h Sat Jul 12 23:05:43 2025 +0200 +++ b/src/ascension/datatypes.h Sun Jul 13 13:35:51 2025 +0200 @@ -214,6 +214,43 @@ } /** + * + * @param x the floating point + * @return if @p x is near zero, returns zero, returns @p x otherwise + */ +static inline float asc_fround_zero(float x) { + if (fabsf(x) < FLT_EPSILON) { + return 0.f; + } else { + return x; + } +} + +/** + * Returns the cosine of x. + * + * This function eliminates result values close to zero. + * + * @param x the angle in radians + * @return the cosine of x + */ +static inline float asc_cos(float x) { + return asc_fround_zero(cosf(x)); +} + +/** + * Returns the sine of x. + * + * This function eliminates result values close to zero. + * + * @param x the angle in radians + * @return the sine of x + */ +static inline float asc_sin(float x) { + return asc_fround_zero(sinf(x)); +} + +/** * Converts a float color (0.0f to 1.0f) to an int color (0 to 255). * * This operation is quite expensive. When you need to use it often, it's