project_files/hwc/rtl/pmath.c
branchwebgl
changeset 7983 02f36c3e7f6c
child 8047 25a4daa6473c
equal deleted inserted replaced
7981:aac257b77842 7983:02f36c3e7f6c
       
     1 #include "pmath.h"
       
     2 #include <math.h>
       
     3 #include <stdlib.h>
       
     4 #include <stdint.h>
       
     5 
       
     6 /*
       
     7  * power raises base to the power power.
       
     8  * This is equivalent to exp(power*ln(base)). Therefore base should be non-negative.
       
     9  */
       
    10 float fpcrtl_power(float base, float exponent)
       
    11 {
       
    12     return exp(exponent * log(base));
       
    13 }
       
    14 
       
    15 /* Currently the games only uses sign of an integer */
       
    16 int fpcrtl_signi(int x)
       
    17 {
       
    18     if(x > 0){
       
    19         return 1;
       
    20     }
       
    21     else if(x < 0){
       
    22         return -1;
       
    23     }
       
    24     else{
       
    25         return 0;
       
    26     }
       
    27 }
       
    28 
       
    29 float fpcrtl_csc(float x)
       
    30 {
       
    31     return 1 / sin(x);
       
    32 }
       
    33 
       
    34 float __attribute__((overloadable)) fpcrtl_abs(float x)
       
    35 {
       
    36     return fabs(x);
       
    37 }
       
    38 double __attribute__((overloadable)) fpcrtl_abs(double x)
       
    39 {
       
    40     return fabs(x);
       
    41 }
       
    42 int __attribute__((overloadable)) fpcrtl_abs(int x)
       
    43 {
       
    44     return abs(x);
       
    45 }
       
    46 
       
    47 int64_t __attribute__((overloadable)) fpcrtl_abs(int64_t x)
       
    48 {
       
    49     return x < 0 ? -x : x;
       
    50 }