misc/liblua/lmathlib.c
author Wuzzy <Wuzzy2@mail.ru>
Thu, 25 Apr 2019 23:01:05 +0200
changeset 14844 e239378a9400
parent 2812 0a24853de796
permissions -rw-r--r--
Prevent entering “/”, “\” and “:” in team and scheme names. The name of teams and schems is saved in the file name itself, so these characters would cause trouble as they are used in path names in Linux and Windows.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     1
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     2
** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     3
** Standard mathematical library
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     4
** See Copyright Notice in lua.h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     5
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     7
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     8
#include <stdlib.h>
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     9
#include <math.h>
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    10
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    11
#define lmathlib_c
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    12
#define LUA_LIB
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    13
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    14
#include "lua.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    15
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    16
#include "lauxlib.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    17
#include "lualib.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    18
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    19
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    20
#undef PI
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    21
#define PI (3.14159265358979323846)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    22
#define RADIANS_PER_DEGREE (PI/180.0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    23
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    24
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    25
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    26
static int math_abs (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    27
  lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    28
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    29
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    30
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    31
static int math_sin (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    32
  lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    33
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    34
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    35
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    36
static int math_sinh (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    37
  lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    38
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    39
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    40
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    41
static int math_cos (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    42
  lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    43
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    44
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    45
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    46
static int math_cosh (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    47
  lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    48
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    49
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    50
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    51
static int math_tan (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    52
  lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    53
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    54
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    55
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    56
static int math_tanh (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    57
  lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    58
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    59
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    60
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    61
static int math_asin (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    62
  lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    63
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    64
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    65
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    66
static int math_acos (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    67
  lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    68
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    69
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    70
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    71
static int math_atan (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    72
  lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    73
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    74
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    75
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    76
static int math_atan2 (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    77
  lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    78
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    79
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    80
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    81
static int math_ceil (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    82
  lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    83
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    84
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    85
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    86
static int math_floor (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    87
  lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    88
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    89
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    90
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    91
static int math_fmod (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    92
  lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    93
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    94
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    95
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    96
static int math_modf (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    97
  double ip;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    98
  double fp = modf(luaL_checknumber(L, 1), &ip);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    99
  lua_pushnumber(L, ip);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   100
  lua_pushnumber(L, fp);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   101
  return 2;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   102
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   103
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   104
static int math_sqrt (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   105
  lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   106
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   107
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   108
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   109
static int math_pow (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   110
  lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   111
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   112
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   113
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   114
static int math_log (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   115
  lua_pushnumber(L, log(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   116
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   117
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   118
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   119
static int math_log10 (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   120
  lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   121
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   122
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   123
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   124
static int math_exp (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   125
  lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   126
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   127
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   128
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   129
static int math_deg (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   130
  lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   131
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   132
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   133
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   134
static int math_rad (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   135
  lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   136
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   137
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   138
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   139
static int math_frexp (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   140
  int e;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   141
  lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   142
  lua_pushinteger(L, e);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   143
  return 2;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   144
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   145
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   146
static int math_ldexp (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   147
  lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   148
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   149
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   150
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   151
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   152
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   153
static int math_min (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   154
  int n = lua_gettop(L);  /* number of arguments */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   155
  lua_Number dmin = luaL_checknumber(L, 1);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   156
  int i;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   157
  for (i=2; i<=n; i++) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   158
    lua_Number d = luaL_checknumber(L, i);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   159
    if (d < dmin)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   160
      dmin = d;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   161
  }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   162
  lua_pushnumber(L, dmin);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   163
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   164
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   165
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   166
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   167
static int math_max (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   168
  int n = lua_gettop(L);  /* number of arguments */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   169
  lua_Number dmax = luaL_checknumber(L, 1);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   170
  int i;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   171
  for (i=2; i<=n; i++) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   172
    lua_Number d = luaL_checknumber(L, i);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   173
    if (d > dmax)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   174
      dmax = d;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   175
  }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   176
  lua_pushnumber(L, dmax);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   177
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   178
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   179
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   180
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   181
static int math_random (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   182
  /* the `%' avoids the (rare) case of r==1, and is needed also because on
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   183
     some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   184
  lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   185
  switch (lua_gettop(L)) {  /* check number of arguments */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   186
    case 0: {  /* no arguments */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   187
      lua_pushnumber(L, r);  /* Number between 0 and 1 */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   188
      break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   189
    }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   190
    case 1: {  /* only upper limit */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   191
      int u = luaL_checkint(L, 1);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   192
      luaL_argcheck(L, 1<=u, 1, "interval is empty");
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   193
      lua_pushnumber(L, floor(r*u)+1);  /* int between 1 and `u' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   194
      break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   195
    }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   196
    case 2: {  /* lower and upper limits */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   197
      int l = luaL_checkint(L, 1);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   198
      int u = luaL_checkint(L, 2);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   199
      luaL_argcheck(L, l<=u, 2, "interval is empty");
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   200
      lua_pushnumber(L, floor(r*(u-l+1))+l);  /* int between `l' and `u' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   201
      break;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   202
    }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   203
    default: return luaL_error(L, "wrong number of arguments");
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   204
  }
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   205
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   206
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   207
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   208
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   209
static int math_randomseed (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   210
  srand(luaL_checkint(L, 1));
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   211
  return 0;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   212
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   213
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   214
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   215
static const luaL_Reg mathlib[] = {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   216
  {"abs",   math_abs},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   217
  {"acos",  math_acos},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   218
  {"asin",  math_asin},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   219
  {"atan2", math_atan2},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   220
  {"atan",  math_atan},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   221
  {"ceil",  math_ceil},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   222
  {"cosh",   math_cosh},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   223
  {"cos",   math_cos},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   224
  {"deg",   math_deg},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   225
  {"exp",   math_exp},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   226
  {"floor", math_floor},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   227
  {"fmod",   math_fmod},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   228
  {"frexp", math_frexp},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   229
  {"ldexp", math_ldexp},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   230
  {"log10", math_log10},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   231
  {"log",   math_log},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   232
  {"max",   math_max},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   233
  {"min",   math_min},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   234
  {"modf",   math_modf},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   235
  {"pow",   math_pow},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   236
  {"rad",   math_rad},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   237
  {"random",     math_random},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   238
  {"randomseed", math_randomseed},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   239
  {"sinh",   math_sinh},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   240
  {"sin",   math_sin},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   241
  {"sqrt",  math_sqrt},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   242
  {"tanh",   math_tanh},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   243
  {"tan",   math_tan},
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   244
  {NULL, NULL}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   245
};
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   246
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   247
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   248
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   249
** Open math library
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   250
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   251
LUALIB_API int luaopen_math (lua_State *L) {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   252
  luaL_register(L, LUA_MATHLIBNAME, mathlib);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   253
  lua_pushnumber(L, PI);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   254
  lua_setfield(L, -2, "pi");
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   255
  lua_pushnumber(L, HUGE_VAL);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   256
  lua_setfield(L, -2, "huge");
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   257
#if defined(LUA_COMPAT_MOD)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   258
  lua_getfield(L, -1, "fmod");
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   259
  lua_setfield(L, -2, "mod");
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   260
#endif
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   261
  return 1;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   262
}
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   263