The Battle for Wesnoth  1.15.12+dev
Classes | Macros | Typedefs | Functions | Variables
lmathlib.cpp File Reference
#include "lprefix.h"
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
Include dependency graph for lmathlib.cpp:

Go to the source code of this file.

Classes

struct  Rand64
 
struct  RanState
 

Macros

#define lmathlib_c
 
#define LUA_LIB
 
#define PI   (l_mathop(3.141592653589793238462643383279502884))
 
#define FIGS   l_floatatt(MANT_DIG)
 
#define trim32(x)   ((x) & 0xffffffffu)
 
#define UONE   ((lu_int32)1)
 
#define scaleFIG   (l_mathop(0.5) / (UONE << (FIGS - 1)))
 

Typedefs

typedef unsigned long lu_int32
 
typedef struct Rand64 Rand64
 

Functions

static int math_abs (lua_State *L)
 
static int math_sin (lua_State *L)
 
static int math_cos (lua_State *L)
 
static int math_tan (lua_State *L)
 
static int math_asin (lua_State *L)
 
static int math_acos (lua_State *L)
 
static int math_atan (lua_State *L)
 
static int math_toint (lua_State *L)
 
static void pushnumint (lua_State *L, lua_Number d)
 
static int math_floor (lua_State *L)
 
static int math_ceil (lua_State *L)
 
static int math_fmod (lua_State *L)
 
static int math_modf (lua_State *L)
 
static int math_sqrt (lua_State *L)
 
static int math_ult (lua_State *L)
 
static int math_log (lua_State *L)
 
static int math_exp (lua_State *L)
 
static int math_deg (lua_State *L)
 
static int math_rad (lua_State *L)
 
static int math_min (lua_State *L)
 
static int math_max (lua_State *L)
 
static int math_type (lua_State *L)
 
static Rand64 packI (lu_int32 h, lu_int32 l)
 
static Rand64 Ishl (Rand64 i, int n)
 
static void Ixor (Rand64 *i1, Rand64 i2)
 
static Rand64 Iadd (Rand64 i1, Rand64 i2)
 
static Rand64 times5 (Rand64 i)
 
static Rand64 times9 (Rand64 i)
 
static Rand64 rotl (Rand64 i, int n)
 
static Rand64 rotl1 (Rand64 i, int n)
 
static Rand64 nextrand (Rand64 *state)
 
static lua_Number I2d (Rand64 x)
 
static lua_Unsigned I2UInt (Rand64 x)
 
static Rand64 Int2I (lua_Unsigned n)
 
static lua_Unsigned project (lua_Unsigned ran, lua_Unsigned n, RanState *state)
 
static int math_random (lua_State *L)
 
static void setseed (lua_State *L, Rand64 *state, lua_Unsigned n1, lua_Unsigned n2)
 
static void randseed (lua_State *L, RanState *state)
 
static int math_randomseed (lua_State *L)
 
static void setrandfunc (lua_State *L)
 
LUAMOD_API int luaopen_math (lua_State *L)
 

Variables

static const luaL_Reg randfuncs []
 
static const luaL_Reg mathlib []
 

Macro Definition Documentation

◆ FIGS

#define FIGS   l_floatatt(MANT_DIG)

Definition at line 252 of file lmathlib.cpp.

Referenced by I2d().

◆ lmathlib_c

#define lmathlib_c

Definition at line 7 of file lmathlib.cpp.

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file lmathlib.cpp.

◆ PI

#define PI   (l_mathop(3.141592653589793238462643383279502884))

Definition at line 26 of file lmathlib.cpp.

Referenced by luaopen_math(), math_deg(), and math_rad().

◆ scaleFIG

#define scaleFIG   (l_mathop(0.5) / (UONE << (FIGS - 1)))

Definition at line 460 of file lmathlib.cpp.

Referenced by I2d().

◆ trim32

#define trim32 (   x)    ((x) & 0xffffffffu)

Definition at line 373 of file lmathlib.cpp.

Referenced by I2d(), I2UInt(), Iadd(), Ishl(), rotl(), and rotl1().

◆ UONE

#define UONE   ((lu_int32)1)

Definition at line 454 of file lmathlib.cpp.

Typedef Documentation

◆ lu_int32

typedef unsigned long lu_int32

Definition at line 353 of file lmathlib.cpp.

◆ Rand64

typedef struct Rand64 Rand64

Function Documentation

◆ I2d()

static lua_Number I2d ( Rand64  x)
static

Definition at line 466 of file lmathlib.cpp.

References FIGS, Rand64::h, Rand64::l, scaleFIG, and trim32.

Referenced by math_random().

◆ I2UInt()

static lua_Unsigned I2UInt ( Rand64  x)
static

Definition at line 501 of file lmathlib.cpp.

References Rand64::h, Rand64::l, and trim32.

Referenced by math_random(), and project().

◆ Iadd()

static Rand64 Iadd ( Rand64  i1,
Rand64  i2 
)
static

Definition at line 401 of file lmathlib.cpp.

References Rand64::h, Rand64::l, packI(), and trim32.

Referenced by times5(), and times9().

◆ Int2I()

static Rand64 Int2I ( lua_Unsigned  n)
static

Definition at line 506 of file lmathlib.cpp.

References packI().

Referenced by setseed().

◆ Ishl()

static Rand64 Ishl ( Rand64  i,
int  n 
)
static

Definition at line 389 of file lmathlib.cpp.

References Rand64::h, Rand64::l, lua_assert, packI(), and trim32.

Referenced by nextrand(), times5(), and times9().

◆ Ixor()

static void Ixor ( Rand64 i1,
Rand64  i2 
)
static

Definition at line 395 of file lmathlib.cpp.

References Rand64::h, and Rand64::l.

Referenced by nextrand().

◆ luaopen_math()

LUAMOD_API int luaopen_math ( lua_State L)

◆ math_abs()

static int math_abs ( lua_State L)
static

◆ math_acos()

static int math_acos ( lua_State L)
static

Definition at line 60 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), and luaL_checknumber().

◆ math_asin()

static int math_asin ( lua_State L)
static

Definition at line 55 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), and luaL_checknumber().

◆ math_atan()

static int math_atan ( lua_State L)
static

Definition at line 65 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), luaL_checknumber(), and luaL_optnumber().

◆ math_ceil()

static int math_ceil ( lua_State L)
static

Definition at line 106 of file lmathlib.cpp.

References d, l_mathop, lua_isinteger(), lua_settop(), luaL_checknumber(), and pushnumint().

◆ math_cos()

static int math_cos ( lua_State L)
static

Definition at line 45 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), and luaL_checknumber().

◆ math_deg()

static int math_deg ( lua_State L)
static

Definition at line 194 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), luaL_checknumber(), and PI.

◆ math_exp()

static int math_exp ( lua_State L)
static

Definition at line 189 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), and luaL_checknumber().

◆ math_floor()

static int math_floor ( lua_State L)
static

Definition at line 95 of file lmathlib.cpp.

References d, l_mathop, lua_isinteger(), lua_settop(), luaL_checknumber(), and pushnumint().

◆ math_fmod()

static int math_fmod ( lua_State L)
static

◆ math_log()

static int math_log ( lua_State L)
static

Definition at line 169 of file lmathlib.cpp.

References l_mathop, lua_isnoneornil, lua_pushnumber(), and luaL_checknumber().

◆ math_max()

static int math_max ( lua_State L)
static

Definition at line 219 of file lmathlib.cpp.

References i, lua_compare(), lua_gettop(), LUA_OPLT, lua_pushvalue(), luaL_argcheck, and n.

◆ math_min()

static int math_min ( lua_State L)
static

Definition at line 205 of file lmathlib.cpp.

References i, lua_compare(), lua_gettop(), LUA_OPLT, lua_pushvalue(), luaL_argcheck, and n.

◆ math_modf()

static int math_modf ( lua_State L)
static

◆ math_rad()

static int math_rad ( lua_State L)
static

Definition at line 199 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), luaL_checknumber(), and PI.

◆ math_random()

static int math_random ( lua_State L)
static

◆ math_randomseed()

static int math_randomseed ( lua_State L)
static

◆ math_sin()

static int math_sin ( lua_State L)
static

Definition at line 40 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), and luaL_checknumber().

◆ math_sqrt()

static int math_sqrt ( lua_State L)
static

Definition at line 156 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), and luaL_checknumber().

◆ math_tan()

static int math_tan ( lua_State L)
static

Definition at line 50 of file lmathlib.cpp.

References l_mathop, lua_pushnumber(), and luaL_checknumber().

◆ math_toint()

static int math_toint ( lua_State L)
static

Definition at line 73 of file lmathlib.cpp.

References lua_pushinteger(), lua_tointegerx(), luaL_checkany(), luaL_pushfail, and n.

◆ math_type()

static int math_type ( lua_State L)
static

◆ math_ult()

static int math_ult ( lua_State L)
static

Definition at line 162 of file lmathlib.cpp.

References a, b, lua_pushboolean(), and luaL_checkinteger().

◆ nextrand()

static Rand64 nextrand ( Rand64 state)
static

Definition at line 436 of file lmathlib.cpp.

References Ishl(), Ixor(), rotl(), rotl1(), t, times5(), and times9().

Referenced by math_random(), project(), and setseed().

◆ packI()

static Rand64 packI ( lu_int32  h,
lu_int32  l 
)
static

Definition at line 381 of file lmathlib.cpp.

References Rand64::h, and Rand64::l.

Referenced by Iadd(), Int2I(), Ishl(), rotl(), and rotl1().

◆ project()

static lua_Unsigned project ( lua_Unsigned  ran,
lua_Unsigned  n,
RanState state 
)
static

Definition at line 531 of file lmathlib.cpp.

References I2UInt(), lua_assert, n, nextrand(), and RanState::s.

Referenced by math_random().

◆ pushnumint()

static void pushnumint ( lua_State L,
lua_Number  d 
)
static

Definition at line 86 of file lmathlib.cpp.

References lua_numbertointeger, lua_pushinteger(), lua_pushnumber(), and n.

Referenced by math_ceil(), math_floor(), and math_modf().

◆ randseed()

static void randseed ( lua_State L,
RanState state 
)
static

Definition at line 610 of file lmathlib.cpp.

References RanState::s, and setseed().

Referenced by math_randomseed(), and setrandfunc().

◆ rotl()

static Rand64 rotl ( Rand64  i,
int  n 
)
static

Definition at line 419 of file lmathlib.cpp.

References Rand64::h, Rand64::l, lua_assert, packI(), and trim32.

Referenced by nextrand().

◆ rotl1()

static Rand64 rotl1 ( Rand64  i,
int  n 
)
static

Definition at line 426 of file lmathlib.cpp.

References Rand64::h, Rand64::l, lua_assert, n, packI(), and trim32.

Referenced by nextrand().

◆ setrandfunc()

static void setrandfunc ( lua_State L)
static

◆ setseed()

static void setseed ( lua_State L,
Rand64 state,
lua_Unsigned  n1,
lua_Unsigned  n2 
)
static

Definition at line 591 of file lmathlib.cpp.

References i, Int2I(), lua_pushinteger(), and nextrand().

Referenced by math_randomseed(), and randseed().

◆ times5()

static Rand64 times5 ( Rand64  i)
static

Definition at line 409 of file lmathlib.cpp.

References Iadd(), and Ishl().

Referenced by nextrand().

◆ times9()

static Rand64 times9 ( Rand64  i)
static

Definition at line 414 of file lmathlib.cpp.

References Iadd(), and Ishl().

Referenced by nextrand().

Variable Documentation

◆ mathlib

const luaL_Reg mathlib[]
static

Definition at line 704 of file lmathlib.cpp.

◆ randfuncs

const luaL_Reg randfuncs[]
static
Initial value:
= {
{"random", math_random},
{"randomseed", math_randomseed},
{NULL, NULL}
}
static int math_randomseed(lua_State *L)
Definition: lmathlib.cpp:617
static int math_random(lua_State *L)
Definition: lmathlib.cpp:556

Definition at line 631 of file lmathlib.cpp.