Downloads containing SEmath.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Devan's Revenge (Intro)Featured Download sAlAmAnDeR Single player 9.6 Download file
TSF with JJ2+ Only: Chaos V1.1Featured Download sAlAmAnDeR Mutator 8.5 Download file

File preview

  1. //Common math functions (v1.0 for Plus Beta Build 2013-10-19 and later) by Sir Ementaler
  2. const float INF=1.0e+40f;
  3. const float NaN=INF*0;
  4. const float pi=3.1415927f;
  5. bool isinf(float x){
  6.   return x==INF||x==-INF;
  7. }
  8. bool isnan(float x){
  9.   return x!=x;
  10. }
  11. bool isfinite(float x){
  12.   return !isnan(x)&&!isinf(x);
  13. }
  14. int sign(int x){
  15.   return x>0?1:x<0?-1:0;
  16. }
  17. float sign(float x){
  18.   return x>0?1:x<0?-1:0;
  19. }
  20. float trunc(float x){
  21.   return x>0?floor(x):ceil(x);
  22. }
  23. float round(float x){
  24.   return trunc(x)+(abs(fraction(x))>=0.5?sign(x):0);
  25. }
  26. int min(int x,int y){
  27.   return x<y?x:y;
  28. }
  29. float min(float x,float y){
  30.   if(isnan(x)) return y;
  31.   if(isnan(y)) return x;
  32.   return x<y?x:y;
  33. }
  34. float min(int x,float y){
  35.   return min(float(x),y);
  36. }
  37. float min(float x,int y){
  38.   return min(x,float(y));
  39. }
  40. int max(int x,int y){
  41.   return x>y?x:y;
  42. }
  43. float max(float x,float y){
  44.   if(isnan(x)) return y;
  45.   if(isnan(y)) return x;
  46.   return x>y?x:y;
  47. }
  48. float max(int x,float y){
  49.   return max(float(x),y);
  50. }
  51. float max(float x,int y){
  52.   return max(x,float(y));
  53. }
  54. float cbrt(float x){
  55.   return pow(x,1.f/3.f);
  56. }
  57. float exp(float x){
  58.   return pow(2.7182818f,x);
  59. }
  60. float log2(float x){
  61.   return log(x)/0.69314718f;
  62. }
  63. float logb(float x,float b){
  64.   if(b==1) return NaN;
  65.   return log(x)/log(b);
  66. }
  67. float asinh(float x){
  68.   return log(x+sqrt(x*x+1));
  69. }
  70. float acosh(float x){
  71.   if(x<1) return NaN;
  72.   return log(x+sqrt(x*x-1));
  73. }
  74. float atanh(float x){
  75.   if(abs(x)>1) return NaN;
  76.   if(abs(x)==1) return sign(x)*INF;
  77.   return log((1+x)/(1-x))/2;
  78. }