project_files/hwc/rtl/pmath.c
author sheepluva
Mon, 05 Aug 2019 00:20:45 +0200
changeset 15295 f382ec6dba11
parent 14197 3e551b0535fb
permissions -rw-r--r--
In hindsight my emscripten-ifdef (70d416a8f63f) is nonsense. As fpcrtl_glShaderSource() would not be defined and lead to compiling issues. So either it's 3 ifdefs (in pas2cRedo, pas2cSystem and misc.c), in order to toggle between fpcrtl_ and the native function, or alternatively have no ifdef for it at all. I'm going with none at all, which means emscripten will compile with the original (const) function prototype, being wrapped by the fpcrtl_ function, same as non-emscripten builds.

#include "pmath.h"
#include <stdlib.h>
#include <math.h>

/* Currently the games only uses sign of an integer */
int fpcrtl_signi(int x)
{
    if(x > 0){
        return 1;
    }
    else if(x < 0){
        return -1;
    }
    else{
        return 0;
    }
}

float fpcrtl_csc(float x)
{
    return 1 / sin(x);
}

float __attribute__((overloadable)) fpcrtl_abs(float x)
{
    return fabsf(x);
}
double __attribute__((overloadable)) fpcrtl_abs(double x)
{
    return fabs(x);
}
long double __attribute__((overloadable)) fpcrtl_abs(long double x)
{
    return fabsl(x);
}
int __attribute__((overloadable)) fpcrtl_abs(int x)
{
    return abs(x);
}

int64_t __attribute__((overloadable)) fpcrtl_abs(int64_t x)
{
    return x < 0 ? -x : x;
}