project_files/hwc/rtl/pmath.c
author nemo
Fri, 12 Apr 2019 11:41:35 -0400
changeset 14797 38e66519e585
parent 14202 3e551b0535fb
permissions -rw-r--r--
ugly hacked in argument for port to remove unc0rr's excuse
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
/* Currently the games only uses sign of an integer */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     6
int fpcrtl_signi(int x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     8
    if(x > 0){
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     9
        return 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    10
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    11
    else if(x < 0){
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    12
        return -1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    14
    else{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    15
        return 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    17
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
float fpcrtl_csc(float x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
    return 1 / sin(x);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    22
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    24
float __attribute__((overloadable)) fpcrtl_abs(float x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    25
{
14190
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 8047
diff changeset
    26
    return fabsf(x);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    27
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    28
double __attribute__((overloadable)) fpcrtl_abs(double x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    29
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    30
    return fabs(x);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    31
}
14190
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 8047
diff changeset
    32
long double __attribute__((overloadable)) fpcrtl_abs(long double x)
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 8047
diff changeset
    33
{
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 8047
diff changeset
    34
    return fabsl(x);
801dc57371c3 Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
Wuzzy <Wuzzy2@mail.ru>
parents: 8047
diff changeset
    35
}
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    36
int __attribute__((overloadable)) fpcrtl_abs(int x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    37
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    38
    return abs(x);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    39
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    40
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    41
int64_t __attribute__((overloadable)) fpcrtl_abs(int64_t x)
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    42
{
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    43
    return x < 0 ? -x : x;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
}