Skip to content

Commit

Permalink
Fix up sincos, sincosf and sincosl to call to browser sin and cos fun…
Browse files Browse the repository at this point in the history
…ctions to fix missing symbols in libc build, and to give better performance than the musl provided ones.
  • Loading branch information
juj committed Dec 17, 2014
1 parent f7651f8 commit b7967e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions system/lib/libc/musl/src/math/sincos.c
Expand Up @@ -13,6 +13,16 @@
#define _GNU_SOURCE
#include "libm.h"

#ifdef __EMSCRIPTEN__
#include <math.h>

// XXX Emscripten: Use the browser-optimized versions of sin and cos, since they are faster.
void sincos(double x, double *s, double *c)
{
*s = sin(x);
*c = cos(x);
}
#else
void sincos(double x, double *sin, double *cos)
{
double y[2], s, c;
Expand Down Expand Up @@ -67,3 +77,4 @@ void sincos(double x, double *sin, double *cos)
break;
}
}
#endif
10 changes: 10 additions & 0 deletions system/lib/libc/musl/src/math/sincosf.c
Expand Up @@ -17,6 +17,10 @@
#define _GNU_SOURCE
#include "libm.h"

#ifdef __EMSCRIPTEN__
#include <math.h>
#endif

/* Small multiples of pi/2 rounded to double precision. */
static const double
s1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */
Expand All @@ -26,6 +30,11 @@ s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */

void sincosf(float x, float *sin, float *cos)
{
#ifdef __EMSCRIPTEN__
// XXX Emscripten: Use the browser-optimized versions of sin and cos, since they are faster.
*sin = sinf(x);
*cos = cosf(x);
#else
double y;
float_t s, c;
uint32_t ix;
Expand Down Expand Up @@ -114,4 +123,5 @@ void sincosf(float x, float *sin, float *cos)
*cos = s;
break;
}
#endif
}
14 changes: 14 additions & 0 deletions system/lib/libc/musl/src/math/sincosl.c
@@ -1,6 +1,18 @@
#define _GNU_SOURCE
#include "libm.h"

#ifdef __EMSCRIPTEN__
#include <math.h>

// XXX Emscripten: Use the browser-optimized versions of sin and cos, since they are faster.
void sincosl(long double x, long double *sin, long double *cos)
{
*sin = sinl(x);
*cos = cosl(x);
}

#else

#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
void sincosl(long double x, long double *sin, long double *cos)
{
Expand Down Expand Up @@ -58,3 +70,5 @@ void sincosl(long double x, long double *sin, long double *cos)
}
}
#endif

#endif

0 comments on commit b7967e6

Please sign in to comment.