w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

numeric.c File Reference
#include <float.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/numeric.h>
#include <mruby/class.h>
#include <mruby/presym.h>
Include dependency graph for numeric.c:

Go to the source code of this file.

Macros

#define FLO_TO_STR_PREC   16
 
#define bit_op(x, y, op1, op2)
 
#define NUMERIC_SHIFT_WIDTH_MAX   (MRB_INT_BIT-1)
 

Functions

mrb_float mrb_to_flo (mrb_state *mrb, mrb_value val)
 
static void int_overflow (mrb_state *mrb, const char *reason)
 
static void int_zerodiv (mrb_state *mrb)
 
static mrb_value int_pow (mrb_state *mrb, mrb_value x)
 
mrb_int mrb_num_div_int (mrb_state *mrb, mrb_int x, mrb_int y)
 
static mrb_value int_div (mrb_state *mrb, mrb_value xv)
 
static mrb_value int_quo (mrb_state *mrb, mrb_value xv)
 
static mrb_value coerce_step_counter (mrb_state *mrb, mrb_value self)
 
static mrb_value flo_pow (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_idiv (mrb_state *mrb, mrb_value xv)
 
mrb_float mrb_num_div_flo (mrb_state *mrb, mrb_float x, mrb_float y)
 
static mrb_value flo_div (mrb_state *mrb, mrb_value xv)
 
static mrb_value flo_to_s (mrb_state *mrb, mrb_value flt)
 
static mrb_value flo_minus (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_mul (mrb_state *mrb, mrb_value x)
 
static void flodivmod (mrb_state *mrb, double x, double y, mrb_float *divp, mrb_float *modp)
 
static mrb_value flo_mod (mrb_state *mrb, mrb_value x)
 
static mrb_value int_eql (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_eql (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_eq (mrb_state *mrb, mrb_value x)
 
static int64_t value_int64 (mrb_state *mrb, mrb_value x)
 
static mrb_value int64_value (mrb_state *mrb, int64_t v)
 
static mrb_value flo_rev (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_and (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_or (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_xor (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_shift (mrb_state *mrb, mrb_value x, mrb_int width)
 
static mrb_value flo_rshift (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_lshift (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_to_f (mrb_state *mrb, mrb_value num)
 
static mrb_value flo_infinite_p (mrb_state *mrb, mrb_value num)
 
static mrb_value flo_finite_p (mrb_state *mrb, mrb_value num)
 
void mrb_check_num_exact (mrb_state *mrb, mrb_float num)
 
static mrb_value flo_floor (mrb_state *mrb, mrb_value num)
 
static mrb_value flo_ceil (mrb_state *mrb, mrb_value num)
 
static mrb_value flo_round (mrb_state *mrb, mrb_value num)
 
static mrb_value flo_truncate (mrb_state *mrb, mrb_value num)
 
static mrb_value flo_nan_p (mrb_state *mrb, mrb_value num)
 
static mrb_value int_to_i (mrb_state *mrb, mrb_value num)
 
static mrb_value fixnum_mul (mrb_state *mrb, mrb_value x, mrb_value y)
 
mrb_value mrb_num_mul (mrb_state *mrb, mrb_value x, mrb_value y)
 
static mrb_value int_mul (mrb_state *mrb, mrb_value x)
 
static void fixdivmod (mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp)
 
static mrb_value int_mod (mrb_state *mrb, mrb_value x)
 
static mrb_value int_divmod (mrb_state *mrb, mrb_value x)
 
static mrb_value flo_divmod (mrb_state *mrb, mrb_value x)
 
static mrb_value int_equal (mrb_state *mrb, mrb_value x)
 
static mrb_value int_rev (mrb_state *mrb, mrb_value num)
 
static mrb_value int_and (mrb_state *mrb, mrb_value x)
 
static mrb_value int_or (mrb_state *mrb, mrb_value x)
 
static mrb_value int_xor (mrb_state *mrb, mrb_value x)
 
static mrb_value lshift (mrb_state *mrb, mrb_int val, mrb_int width)
 
static mrb_value rshift (mrb_state *mrb, mrb_int val, mrb_int width)
 
static mrb_value int_lshift (mrb_state *mrb, mrb_value x)
 
static mrb_value int_rshift (mrb_state *mrb, mrb_value x)
 
static mrb_value int_to_f (mrb_state *mrb, mrb_value num)
 
mrb_value mrb_flo_to_fixnum (mrb_state *mrb, mrb_value x)
 
static mrb_value fixnum_plus (mrb_state *mrb, mrb_value x, mrb_value y)
 
mrb_value mrb_num_plus (mrb_state *mrb, mrb_value x, mrb_value y)
 
static mrb_value int_plus (mrb_state *mrb, mrb_value self)
 
static mrb_value fixnum_minus (mrb_state *mrb, mrb_value x, mrb_value y)
 
mrb_value mrb_num_minus (mrb_state *mrb, mrb_value x, mrb_value y)
 
static mrb_value int_minus (mrb_state *mrb, mrb_value self)
 
mrb_value mrb_fixnum_to_str (mrb_state *mrb, mrb_value x, mrb_int base)
 
static mrb_value int_to_s (mrb_state *mrb, mrb_value self)
 
static mrb_int cmpnum (mrb_state *mrb, mrb_value v1, mrb_value v2)
 
static mrb_value num_cmp (mrb_state *mrb, mrb_value self)
 
static void cmperr (mrb_state *mrb, mrb_value v1, mrb_value v2)
 
static mrb_value num_lt (mrb_state *mrb, mrb_value self)
 
static mrb_value num_le (mrb_state *mrb, mrb_value self)
 
static mrb_value num_gt (mrb_state *mrb, mrb_value self)
 
static mrb_value num_ge (mrb_state *mrb, mrb_value self)
 
mrb_int mrb_cmp (mrb_state *mrb, mrb_value obj1, mrb_value obj2)
 
static mrb_value num_finite_p (mrb_state *mrb, mrb_value self)
 
static mrb_value num_infinite_p (mrb_state *mrb, mrb_value self)
 
static mrb_value flo_plus (mrb_state *mrb, mrb_value x)
 
void mrb_init_numeric (mrb_state *mrb)
 

Macro Definition Documentation

◆ bit_op

#define bit_op (   x,
  y,
  op1,
  op2 
)
Value:
do {\
if (mrb_integer_p(y)) return mrb_int_value(mrb, (mrb_integer(x) op2 mrb_integer(y))); \
return flo_ ## op1(mrb, mrb_float_value(mrb, (mrb_float)mrb_integer(x)));\
} while(0)
#define mrb_integer(o)
Definition: boxing_nan.h:71
#define mrb_integer_p(o)
Definition: boxing_word.h:139
kerning y
Definition: ttdriver.c:212
float x
Definition: cordic.py:15
static mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
Definition: value.h:273
double mrb_float
Definition: value.h:85
static mrb_value mrb_int_value(struct mrb_state *mrb, mrb_int i)
Definition: value.h:294

Definition at line 1087 of file numeric.c.

◆ FLO_TO_STR_PREC

#define FLO_TO_STR_PREC   16

Definition at line 30 of file numeric.c.

◆ NUMERIC_SHIFT_WIDTH_MAX

#define NUMERIC_SHIFT_WIDTH_MAX   (MRB_INT_BIT-1)

Definition at line 1141 of file numeric.c.

Function Documentation

◆ cmperr()

static void cmperr ( mrb_state mrb,
mrb_value  v1,
mrb_value  v2 
)
static

Definition at line 1514 of file numeric.c.

References E_ARGUMENT_ERROR, mrb_raisef(), v1, and v2.

Referenced by num_ge(), num_gt(), num_le(), and num_lt().

◆ cmpnum()

static mrb_int cmpnum ( mrb_state mrb,
mrb_value  v1,
mrb_value  v2 
)
static

Definition at line 1452 of file numeric.c.

References mrb_integer, mrb_to_flo(), MRB_TT_FLOAT, MRB_TT_INTEGER, mrb_type(), v1, v2, cordic::x, and y.

Referenced by mrb_cmp(), num_cmp(), num_ge(), num_gt(), num_le(), and num_lt().

◆ coerce_step_counter()

static mrb_value coerce_step_counter ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 194 of file numeric.c.

References mrb_Float(), mrb_float_p, mrb_get_args(), num, and step().

Referenced by mrb_init_numeric().

◆ fixdivmod()

static void fixdivmod ( mrb_state mrb,
mrb_int  x,
mrb_int  y,
mrb_int divp,
mrb_int modp 
)
static

Definition at line 928 of file numeric.c.

References div(), int_overflow(), int_zerodiv(), mod(), MRB_INT_MIN, cordic::x, and y.

Referenced by int_divmod(), and int_mod().

◆ fixnum_minus()

◆ fixnum_mul()

◆ fixnum_plus()

◆ flo_and()

static mrb_value flo_and ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 530 of file numeric.c.

References int64_value(), mrb_get_arg1(), v1, v2, value_int64(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_ceil()

static mrb_value flo_ceil ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 728 of file numeric.c.

References ceil(), f, mrb_check_num_exact(), mrb_int_value(), and num.

Referenced by mrb_init_numeric().

◆ flo_div()

static mrb_value flo_div ( mrb_state mrb,
mrb_value  xv 
)
static

Definition at line 254 of file numeric.c.

References mrb_float_value(), mrb_get_args(), mrb_num_div_flo(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_divmod()

static mrb_value flo_divmod ( mrb_state mrb,
mrb_value  x 
)
static

◆ flo_eq()

static mrb_value flo_eq ( mrb_state mrb,
mrb_value  x 
)
static

◆ flo_eql()

static mrb_value flo_eql ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 456 of file numeric.c.

References mrb_bool_value(), mrb_false_value(), mrb_float_p, mrb_get_arg1(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_finite_p()

static mrb_value flo_finite_p ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 675 of file numeric.c.

References mrb_bool_value(), and num.

Referenced by mrb_init_numeric().

◆ flo_floor()

static mrb_value flo_floor ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 705 of file numeric.c.

References f, floor, mrb_check_num_exact(), mrb_int_value(), and num.

Referenced by mrb_init_numeric().

◆ flo_idiv()

static mrb_value flo_idiv ( mrb_state mrb,
mrb_value  xv 
)
static

Definition at line 228 of file numeric.c.

References div(), mrb_get_args(), mrb_int_value(), mrb_num_div_int(), and y.

Referenced by mrb_init_numeric().

◆ flo_infinite_p()

static mrb_value flo_infinite_p ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 653 of file numeric.c.

References mrb_fixnum_value(), mrb_nil_value(), and num.

Referenced by mrb_init_numeric().

◆ flo_lshift()

static mrb_value flo_lshift ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 617 of file numeric.c.

References flo_shift(), mrb_get_args(), width, and cordic::x.

Referenced by mrb_init_numeric().

◆ flo_minus()

static mrb_value flo_minus ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 345 of file numeric.c.

References mrb_float_value(), mrb_get_arg1(), mrb_to_flo(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_mod()

static mrb_value flo_mod ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 423 of file numeric.c.

References flodivmod(), mod(), mrb_float_value(), mrb_get_arg1(), mrb_to_flo(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_mul()

static mrb_value flo_mul ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 362 of file numeric.c.

References mrb_float_value(), mrb_get_arg1(), mrb_to_flo(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_nan_p()

static mrb_value flo_nan_p ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 843 of file numeric.c.

References mrb_bool_value(), and num.

Referenced by mrb_init_numeric().

◆ flo_or()

static mrb_value flo_or ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 541 of file numeric.c.

References int64_value(), mrb_get_arg1(), v1, v2, value_int64(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_plus()

static mrb_value flo_plus ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 1610 of file numeric.c.

References mrb_float_value(), mrb_get_arg1(), mrb_to_flo(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_pow()

static mrb_value flo_pow ( mrb_state mrb,
mrb_value  x 
)
static

Document-class: Float

Float objects represent inexact real numbers using the native architecture's double-precision floating point representation.

Definition at line 220 of file numeric.c.

References d, mrb_float_value(), mrb_get_arg1(), mrb_to_flo(), pow(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flo_rev()

static mrb_value flo_rev ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 523 of file numeric.c.

References int64_value(), v1, value_int64(), and cordic::x.

Referenced by mrb_init_numeric().

◆ flo_round()

static mrb_value flo_round ( mrb_state mrb,
mrb_value  num 
)
static

◆ flo_rshift()

static mrb_value flo_rshift ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 607 of file numeric.c.

References flo_shift(), mrb_get_args(), MRB_INT_BIT, MRB_INT_MIN, width, and cordic::x.

Referenced by mrb_init_numeric().

◆ flo_shift()

static mrb_value flo_shift ( mrb_state mrb,
mrb_value  x,
mrb_int  width 
)
static

◆ flo_to_f()

static mrb_value flo_to_f ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 634 of file numeric.c.

References num.

Referenced by mrb_init_numeric().

◆ flo_to_s()

◆ flo_truncate()

static mrb_value flo_truncate ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 831 of file numeric.c.

References ceil(), f, floor, mrb_check_num_exact(), mrb_int_value(), and num.

Referenced by mrb_init_numeric().

◆ flo_xor()

static mrb_value flo_xor ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 552 of file numeric.c.

References int64_value(), mrb_get_arg1(), v1, v2, value_int64(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ flodivmod()

static void flodivmod ( mrb_state mrb,
double  x,
double  y,
mrb_float divp,
mrb_float modp 
)
static

Definition at line 370 of file numeric.c.

References div(), exit(), fmod(), INFINITY, mod(), round, cordic::x, and y.

Referenced by flo_divmod(), flo_mod(), int_divmod(), and int_mod().

◆ int64_value()

static mrb_value int64_value ( mrb_state mrb,
int64_t  v 
)
static

Definition at line 514 of file numeric.c.

References int_overflow(), mrb_fixnum_value(), TYPED_FIXABLE, and v.

Referenced by flo_and(), flo_or(), flo_rev(), and flo_xor().

◆ int_and()

static mrb_value int_and ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 1102 of file numeric.c.

References and, bit_op, mrb_get_arg1(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ int_div()

static mrb_value int_div ( mrb_state mrb,
mrb_value  xv 
)
static

Definition at line 154 of file numeric.c.

References div(), mrb_get_args(), mrb_int_value(), mrb_integer, mrb_num_div_int(), and y.

Referenced by mrb_init_numeric().

◆ int_divmod()

◆ int_eql()

static mrb_value int_eql ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 446 of file numeric.c.

References mrb_bool_value(), mrb_false_value(), mrb_get_arg1(), mrb_integer, mrb_integer_p, cordic::x, and y.

Referenced by mrb_init_numeric().

◆ int_equal()

static mrb_value int_equal ( mrb_state mrb,
mrb_value  x 
)
static

◆ int_lshift()

static mrb_value int_lshift ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 1185 of file numeric.c.

References lshift(), mrb_get_args(), MRB_INT_BIT, MRB_INT_MIN, mrb_integer, rshift(), val, width, and cordic::x.

Referenced by mrb_init_numeric().

◆ int_minus()

static mrb_value int_minus ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1385 of file numeric.c.

References fixnum_minus(), mrb_get_arg1(), and other.

Referenced by mrb_init_numeric().

◆ int_mod()

◆ int_mul()

static mrb_value int_mul ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 920 of file numeric.c.

References fixnum_mul(), mrb_get_arg1(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ int_or()

static mrb_value int_or ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 1118 of file numeric.c.

References bit_op, mrb_get_arg1(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ int_overflow()

static void int_overflow ( mrb_state mrb,
const char *  reason 
)
static

◆ int_plus()

static mrb_value int_plus ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1330 of file numeric.c.

References fixnum_plus(), mrb_get_arg1(), and other.

Referenced by mrb_init_numeric().

◆ int_pow()

◆ int_quo()

static mrb_value int_quo ( mrb_state mrb,
mrb_value  xv 
)
static

Definition at line 172 of file numeric.c.

References int_zerodiv(), mrb_fixnum_value(), mrb_float_value(), mrb_get_args(), mrb_integer, and y.

Referenced by mrb_init_numeric().

◆ int_rev()

static mrb_value int_rev ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 1072 of file numeric.c.

References mrb_int_value(), mrb_integer, and num.

Referenced by mrb_init_numeric().

◆ int_rshift()

static mrb_value int_rshift ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 1211 of file numeric.c.

References int_overflow(), lshift(), mrb_get_args(), MRB_INT_MIN, mrb_integer, rshift(), val, width, and cordic::x.

Referenced by mrb_init_numeric().

◆ int_to_f()

static mrb_value int_to_f ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 1239 of file numeric.c.

References mrb_float_value(), mrb_integer, and num.

Referenced by mrb_init_numeric().

◆ int_to_i()

static mrb_value int_to_i ( mrb_state mrb,
mrb_value  num 
)
static

Definition at line 866 of file numeric.c.

References num.

Referenced by mrb_init_numeric().

◆ int_to_s()

static mrb_value int_to_s ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1442 of file numeric.c.

References base, mrb_fixnum_to_str(), and mrb_get_args().

Referenced by mrb_init_numeric().

◆ int_xor()

static mrb_value int_xor ( mrb_state mrb,
mrb_value  x 
)
static

Definition at line 1134 of file numeric.c.

References bit_op, mrb_get_arg1(), cordic::x, and y.

Referenced by mrb_init_numeric().

◆ int_zerodiv()

static void int_zerodiv ( mrb_state mrb)
static

Definition at line 62 of file numeric.c.

References E_ZERODIV_ERROR, and mrb_raise().

Referenced by fixdivmod(), int_quo(), and mrb_num_div_int().

◆ lshift()

◆ mrb_check_num_exact()

void mrb_check_num_exact ( mrb_state mrb,
mrb_float  num 
)

◆ mrb_cmp()

◆ mrb_fixnum_to_str()

◆ mrb_flo_to_fixnum()

◆ mrb_init_numeric()

◆ mrb_num_div_flo()

mrb_float mrb_num_div_flo ( mrb_state mrb,
mrb_float  x,
mrb_float  y 
)

Definition at line 238 of file numeric.c.

References f, INFINITY, cordic::x, and y.

Referenced by flo_div(), and mrb_vm_exec().

◆ mrb_num_div_int()

mrb_int mrb_num_div_int ( mrb_state mrb,
mrb_int  x,
mrb_int  y 
)

Definition at line 123 of file numeric.c.

References div(), int_overflow(), int_zerodiv(), MRB_INT_MIN, cordic::x, and y.

Referenced by flo_idiv(), int_div(), and mrb_vm_exec().

◆ mrb_num_minus()

◆ mrb_num_mul()

◆ mrb_num_plus()

◆ mrb_to_flo()

◆ num_cmp()

static mrb_value num_cmp ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1503 of file numeric.c.

References cmpnum(), mrb_fixnum_value(), mrb_get_arg1(), mrb_nil_value(), n, and other.

Referenced by mrb_init_numeric().

◆ num_finite_p()

static mrb_value num_finite_p ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1589 of file numeric.c.

References mrb_true_value().

Referenced by mrb_init_numeric().

◆ num_ge()

static mrb_value num_ge ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1556 of file numeric.c.

References cmperr(), cmpnum(), mrb_false_value(), mrb_get_arg1(), mrb_true_value(), n, and other.

Referenced by mrb_init_numeric().

◆ num_gt()

static mrb_value num_gt ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1544 of file numeric.c.

References cmperr(), cmpnum(), mrb_false_value(), mrb_get_arg1(), mrb_true_value(), n, and other.

Referenced by mrb_init_numeric().

◆ num_infinite_p()

static mrb_value num_infinite_p ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1595 of file numeric.c.

References mrb_false_value().

Referenced by mrb_init_numeric().

◆ num_le()

static mrb_value num_le ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1532 of file numeric.c.

References cmperr(), cmpnum(), mrb_false_value(), mrb_get_arg1(), mrb_true_value(), n, and other.

Referenced by mrb_init_numeric().

◆ num_lt()

static mrb_value num_lt ( mrb_state mrb,
mrb_value  self 
)
static

Definition at line 1520 of file numeric.c.

References cmperr(), cmpnum(), mrb_false_value(), mrb_get_arg1(), mrb_true_value(), n, and other.

Referenced by mrb_init_numeric().

◆ rshift()

◆ value_int64()

static int64_t value_int64 ( mrb_state mrb,
mrb_value  x 
)
static