project_files/hwc/rtl/pmath.c
author unc0rr
Sat, 16 Dec 2017 23:26:13 +0100
changeset 12854 28cb18c5e712
parent 8047 25a4daa6473c
child 14185 801dc57371c3
permissions -rw-r--r--
Add new qmlfrontend project template
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     1
#include "pmath.h"
8047
25a4daa6473c cleanup headers, remove -I . from rtl lib to save a few warnings
koda
parents: 7983
diff changeset
     2
#include <stdlib.h>
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     3
#include <math.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     4
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     5
/*
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     6
 * power raises base to the power power.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
 * This is equivalent to exp(power*ln(base)). Therefore base should be non-negative.
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     8
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     9
float fpcrtl_power(float base, float exponent)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    10
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    11
    return exp(exponent * log(base));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    12
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    14
/* Currently the games only uses sign of an integer */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    15
int fpcrtl_signi(int x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    17
    if(x > 0){
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
        return 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
    else if(x < 0){
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
        return -1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    22
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
    else{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    24
        return 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    25
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    26
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    27
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    28
float fpcrtl_csc(float x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    29
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    30
    return 1 / sin(x);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    31
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    32
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    33
float __attribute__((overloadable)) fpcrtl_abs(float x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    34
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    35
    return fabs(x);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    36
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    37
double __attribute__((overloadable)) fpcrtl_abs(double x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    38
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    39
    return fabs(x);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    40
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    41
int __attribute__((overloadable)) fpcrtl_abs(int x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    42
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    43
    return abs(x);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    45
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
int64_t __attribute__((overloadable)) fpcrtl_abs(int64_t x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    48
    return x < 0 ? -x : x;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    49
}