Ruby: internal/numeric.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Enumerations | Functions
numeric.h File Reference

Internal header for Numeric. More...

`#include "internal/bignum.h"`
`#include "internal/bits.h"`
`#include "internal/fixnum.h"`
`#include "internal/vm.h"`
`#include "ruby/intern.h"`
`#include "ruby/ruby.h"`

Go to the source code of this file.

## Data Structures
struct | RFloat

## Macros
#define | ROUND_TO(mode, even, up, down)
#define | ROUND_FUNC(mode, name) ROUND_TO(mode, name##_half_even, name##_half_up, name##_half_down)
#define | ROUND_CALL(mode, name, args)
#define | ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
#define | RFLOAT(obj) ((struct RFloat *)(obj))
#define | rb_float_value rb_float_value_inline
#define | rb_float_new rb_float_new_inline

## Enumerations
enum | ruby_num_rounding_mode { RUBY_NUM_ROUND_HALF_UP , RUBY_NUM_ROUND_HALF_EVEN , RUBY_NUM_ROUND_HALF_DOWN , RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT }

## Functions
int | rb_num_to_uint (VALUE val, unsigned int *ret)
VALUE | ruby_num_interval_step_size (VALUE from, VALUE to, VALUE step, int excl)
double | ruby_float_step_size (double beg, double end, double unit, int excl)
int | ruby_float_step (VALUE from, VALUE to, VALUE step, int excl, int allow_endless)
int | rb_num_negative_p (VALUE)
VALUE | rb_int_succ (VALUE num)
VALUE | rb_float_uminus (VALUE num)
VALUE | rb_int_plus (VALUE x, VALUE y)
VALUE | rb_float_plus (VALUE x, VALUE y)
VALUE | rb_int_minus (VALUE x, VALUE y)
VALUE | rb_float_minus (VALUE x, VALUE y)
VALUE | rb_int_mul (VALUE x, VALUE y)
VALUE | rb_float_mul (VALUE x, VALUE y)
VALUE | rb_float_div (VALUE x, VALUE y)
VALUE | rb_int_idiv (VALUE x, VALUE y)
VALUE | rb_int_modulo (VALUE x, VALUE y)
VALUE | rb_int2str (VALUE num, int base)
VALUE | rb_fix_plus (VALUE x, VALUE y)
VALUE | rb_int_gt (VALUE x, VALUE y)
VALUE | rb_float_gt (VALUE x, VALUE y)
VALUE | rb_int_ge (VALUE x, VALUE y)
enum ruby_num_rounding_mode | rb_num_get_rounding_option (VALUE opts)
double | rb_int_fdiv_double (VALUE x, VALUE y)
VALUE | rb_int_pow (VALUE x, VALUE y)
VALUE | rb_float_pow (VALUE x, VALUE y)
VALUE | rb_int_cmp (VALUE x, VALUE y)
VALUE | rb_int_equal (VALUE x, VALUE y)
VALUE | rb_int_divmod (VALUE x, VALUE y)
VALUE | rb_int_and (VALUE x, VALUE y)
VALUE | rb_int_lshift (VALUE x, VALUE y)
VALUE | rb_int_div (VALUE x, VALUE y)
int | rb_int_positive_p (VALUE num)
int | rb_int_negative_p (VALUE num)
VALUE | rb_num_pow (VALUE x, VALUE y)
VALUE | rb_float_ceil (VALUE num, int ndigits)
VALUE | rb_float_floor (VALUE x, int ndigits)
VALUE | rb_float_abs (VALUE flt)
VALUE | rb_int_positive_pow (long x, unsigned long y)
VALUE | rb_flo_div_flo (VALUE x, VALUE y)
double | ruby_float_mod (double x, double y)
VALUE | rb_float_equal (VALUE x, VALUE y)
int | rb_float_cmp (VALUE x, VALUE y)
VALUE | rb_float_eql (VALUE x, VALUE y)
VALUE | rb_fix_aref (VALUE fix, VALUE idx)
VALUE | rb_int_zero_p (VALUE num)
VALUE | rb_int_even_p (VALUE num)
VALUE | rb_int_odd_p (VALUE num)
VALUE | rb_int_abs (VALUE num)
VALUE | rb_int_bit_length (VALUE num)
VALUE | rb_int_uminus (VALUE num)
VALUE | rb_int_comp (VALUE num)

## Detailed Description

Internal header for Numeric.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Definition in file numeric.h.

## Macro Definition Documentation

## ◆ rb_float_new

#define rb_float_new rb_float_new_inline

Definition at line 95 of file numeric.h.

## ◆ rb_float_value

#define rb_float_value rb_float_value_inline

Definition at line 94 of file numeric.h.

## ◆ RFLOAT

#define RFLOAT | ( |  | obj | ) | ((struct RFloat *)(obj))

Definition at line 44 of file numeric.h.

## ◆ ROUND_CALL

#define ROUND_CALL | ( |  | mode,
|  |  | name,
|  |  | args
| ) |  |

Value:
ROUND_TO(mode, name##_half_even args, \
name##_half_up args, name##_half_down args)
ROUND_TO
#define ROUND_TO(mode, even, up, down)
Definition: numeric.h:19
mode
const char int mode
Definition: ioapi.h:137
name
const char * name
Definition: nkf.c:208

Definition at line 24 of file numeric.h.

## ◆ ROUND_DEFAULT

#define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP

Definition at line 29 of file numeric.h.

## ◆ ROUND_FUNC

#define ROUND_FUNC | ( |  | mode,
|  |  | name
| ) |  | ROUND_TO(mode, name##_half_even, name##_half_up, name##_half_down)

Definition at line 22 of file numeric.h.

## ◆ ROUND_TO

#define ROUND_TO | ( |  | mode,
|  |  | even,
|  |  | up,
|  |  | down
| ) |  |

Value:
((mode) == RUBY_NUM_ROUND_HALF_EVEN ? even : \
(mode) == RUBY_NUM_ROUND_HALF_UP ? up : down)
RUBY_NUM_ROUND_HALF_EVEN
@ RUBY_NUM_ROUND_HALF_EVEN
Definition: numeric.h:34
RUBY_NUM_ROUND_HALF_UP
@ RUBY_NUM_ROUND_HALF_UP
Definition: numeric.h:33

Definition at line 19 of file numeric.h.

## Enumeration Type Documentation

## ◆ ruby_num_rounding_mode

enum ruby_num_rounding_mode

Enumerator
RUBY_NUM_ROUND_HALF_UP |
RUBY_NUM_ROUND_HALF_EVEN |
RUBY_NUM_ROUND_HALF_DOWN |
RUBY_NUM_ROUND_DEFAULT |

Definition at line 32 of file numeric.h.

## Function Documentation

## ◆ rb_fix_aref()

VALUE rb_fix_aref | ( | VALUE | fix,
|  | VALUE | idx
| ) |  |

Definition at line 4613 of file numeric.c.

References CHAR_BIT, FIX2LONG, FIXNUM_P, INT2FIX, rb_big_norm(), and rb_to_int().

## ◆ rb_fix_plus()

VALUE rb_fix_plus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3591 of file numeric.c.

## ◆ rb_flo_div_flo()

VALUE rb_flo_div_flo | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1140 of file numeric.c.

References DBL2NUM, num, and RFLOAT_VALUE.

Referenced by rb_big_fdiv_double(), and rb_rational_div().

## ◆ rb_float_abs()

VALUE rb_float_abs | ( | VALUE | flt | ) |

Definition at line 1732 of file numeric.c.

References DBL2NUM, and RFLOAT_VALUE.

Referenced by Init_Numeric().

## ◆ rb_float_ceil()

VALUE rb_float_ceil | ( | VALUE | num,
|  | int | ndigits
| ) |  |

Definition at line 2059 of file numeric.c.

References DBL2NUM, f, INT2FIX, num, and RFLOAT_VALUE.

## ◆ rb_float_cmp()

int rb_float_cmp | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1521 of file numeric.c.

References NUM2INT.

## ◆ rb_float_div()

VALUE rb_float_div | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1156 of file numeric.c.

References DBL2NUM, FIX2LONG, num, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by fun2(), and Init_Numeric().

## ◆ rb_float_eql()

VALUE rb_float_eql | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1688 of file numeric.c.

References isnan, Qfalse, Qtrue, RFLOAT_VALUE, and T_FLOAT.

## ◆ rb_float_equal()

VALUE rb_float_equal | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1417 of file numeric.c.

References isnan, Qfalse, Qtrue, rb_integer_float_eq(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

## ◆ rb_float_floor()

VALUE rb_float_floor | ( | VALUE | x,
|  | int | ndigits
| ) |  |

Definition at line 1935 of file numeric.c.

References DBL2NUM, f, INT2FIX, num, and RFLOAT_VALUE.

## ◆ rb_float_gt()

VALUE rb_float_gt | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1537 of file numeric.c.

References FIX2LONG, FIXNUM_P, isnan, Qfalse, Qtrue, rb_integer_float_cmp(), rb_num_coerce_relop(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_minus()

VALUE rb_float_minus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1078 of file numeric.c.

References DBL2NUM, FIX2LONG, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_mul()

VALUE rb_float_mul | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1102 of file numeric.c.

References DBL2NUM, FIX2LONG, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_plus()

VALUE rb_float_plus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1054 of file numeric.c.

References DBL2NUM, FIX2LONG, rb_big2dbl(), rb_num_coerce_bin(), RFLOAT_VALUE, T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric().

## ◆ rb_float_pow()

VALUE rb_float_pow | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1328 of file numeric.c.

References DBL2NUM, FIX2LONG, idPow, INT2FIX, rb_big2dbl(), rb_dbl_complex_new_polar_pi(), rb_num_coerce_bin(), RFLOAT_VALUE, round(), T_BIGNUM, T_FIXNUM, and T_FLOAT.

Referenced by Init_Numeric(), rb_num_pow(), and rb_rational_pow().

## ◆ rb_float_uminus()

VALUE rb_float_uminus | ( | VALUE | num | ) |

Definition at line 1041 of file numeric.c.

References DBL2NUM, and RFLOAT_VALUE.

Referenced by Init_Numeric().

## ◆ rb_int2str()

VALUE rb_int2str | ( | VALUE | num,
|  | int | base
| ) |  |

Definition at line 3549 of file numeric.c.

References FIXNUM_P, rb_any_to_s(), rb_big2str(), rb_fix2str(), and T_BIGNUM.

Referenced by rb_str_format().

## ◆ rb_int_abs()

VALUE rb_int_abs | ( | VALUE | num | ) |

Definition at line 4826 of file numeric.c.

References FIXNUM_P, num, Qnil, rb_big_abs(), and T_BIGNUM.

Referenced by rb_rational_abs().

## ◆ rb_int_and()

VALUE rb_int_and | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4436 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_and(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_bit_length()

VALUE rb_int_bit_length | ( | VALUE | num | ) |

Definition at line 4881 of file numeric.c.

References FIXNUM_P, num, Qnil, rb_big_bit_length(), and T_BIGNUM.

## ◆ rb_int_cmp()

VALUE rb_int_cmp | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4196 of file numeric.c.

References FIXNUM_P, rb_big_cmp(), rb_eNotImpError, rb_obj_classname(), rb_raise(), and T_BIGNUM.

Referenced by Init_Numeric(), and rb_rational_cmp().

## ◆ rb_int_comp()

VALUE rb_int_comp | ( | VALUE | num | ) |

Definition at line 4372 of file numeric.c.

References FIXNUM_P, num, Qnil, rb_big_comp(), and T_BIGNUM.

## ◆ rb_int_div()

VALUE rb_int_div | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3803 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_div(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_divmod()

VALUE rb_int_divmod | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3950 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_divmod(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_equal()

VALUE rb_int_equal | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4147 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_eq(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_even_p()

VALUE rb_int_even_p | ( | VALUE | num | ) |

Definition at line 3273 of file numeric.c.

References num.

## ◆ rb_int_fdiv_double()

double rb_int_fdiv_double | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3715 of file numeric.c.

References FIXNUM_P, gcd(), nan(), rb_big_fdiv_double(), rb_gcd(), rb_int_idiv(), RB_INTEGER_TYPE_P, and T_BIGNUM.

Referenced by rb_int_fdiv().

## ◆ rb_int_ge()

VALUE rb_int_ge | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4276 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_ge(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_gt()

VALUE rb_int_gt | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4236 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_gt(), and T_BIGNUM.

Referenced by Init_Numeric().

## ◆ rb_int_idiv()

VALUE rb_int_idiv | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3830 of file numeric.c.

References FIXNUM_P, rb_big_idiv(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_int_fdiv_double(), and rb_str_format().

## ◆ rb_int_lshift()

VALUE rb_int_lshift | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4553 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_lshift(), and T_BIGNUM.

Referenced by Init_Numeric(), and rb_flt_rationalize().

## ◆ rb_int_minus()

VALUE rb_int_minus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3636 of file numeric.c.

References FIXNUM_P, rb_big_minus(), rb_num_coerce_bin(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_flt_rationalize(), rb_int_truncate(), rb_rational_cmp(), and rb_rational_minus().

## ◆ rb_int_modulo()

VALUE rb_int_modulo | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3873 of file numeric.c.

References FIXNUM_P, rb_big_modulo(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_int_powm(), rb_int_truncate(), and rb_io_ungetbyte().

## ◆ rb_int_mul()

VALUE rb_int_mul | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3686 of file numeric.c.

References FIXNUM_P, rb_big_mul(), rb_num_coerce_bin(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_flt_rationalize(), rb_rational_cmp(), rb_rational_minus(), rb_rational_plus(), and rb_str_format().

## ◆ rb_int_negative_p()

int rb_int_negative_p | ( | VALUE | num | ) |

Definition at line 313 of file numeric.c.

References num.

Referenced by rb_int_powm().

## ◆ rb_int_odd_p()

VALUE rb_int_odd_p | ( | VALUE | num | ) |

Definition at line 3243 of file numeric.c.

References assert, FIXNUM_P, num, Qfalse, Qtrue, rb_big_odd_p(), and T_BIGNUM.

Referenced by rb_rational_pow().

## ◆ rb_int_plus()

VALUE rb_int_plus | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 3597 of file numeric.c.

References FIXNUM_P, rb_big_plus(), rb_num_coerce_bin(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_flt_rationalize(), rb_int_truncate(), rb_rational_plus(), and rb_str_format().

## ◆ rb_int_positive_p()

int rb_int_positive_p | ( | VALUE | num | ) |

Definition at line 307 of file numeric.c.

References num.

## ◆ rb_int_positive_pow()

VALUE rb_int_positive_pow | ( | long | x,
|  | unsigned long | y
| ) |  |

Definition at line 4022 of file numeric.c.

## ◆ rb_int_pow()

VALUE rb_int_pow | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4088 of file numeric.c.

References FIXNUM_P, Qnil, rb_big_pow(), and T_BIGNUM.

Referenced by Init_Numeric(), rb_int_powm(), rb_num_pow(), and rb_rational_pow().

## ◆ rb_int_succ()

VALUE rb_int_succ | ( | VALUE | num | ) |

Definition at line 3337 of file numeric.c.

References FIX2LONG, FIXNUM_P, INT2FIX, LONG2NUM, num, rb_big_plus(), and T_BIGNUM.

## ◆ rb_int_uminus()

VALUE rb_int_uminus | ( | VALUE | num | ) |

Definition at line 3466 of file numeric.c.

References assert, FIXNUM_P, num, rb_big_uminus(), and T_BIGNUM.

Referenced by rb_complex_pow(), rb_int_powm(), rb_rational_pow(), rb_rational_raw(), and rb_rational_uminus().

## ◆ rb_int_zero_p()

VALUE rb_int_zero_p | ( | VALUE | num | ) |

Definition at line 800 of file numeric.c.

References num.

## ◆ rb_num_get_rounding_option()

enum ruby_num_rounding_mode rb_num_get_rounding_option | ( | VALUE | opts | ) |

Definition at line 205 of file numeric.c.

References NIL_P, PRIsVALUE, rb_check_string_type(), rb_eArgError, rb_get_kwargs(), rb_memcicmp(), rb_must_asciicompat(), rb_raise(), rb_sym2str(), RSTRING_LEN, RSTRING_PTR, RUBY_NUM_ROUND_DEFAULT, RUBY_NUM_ROUND_HALF_DOWN, RUBY_NUM_ROUND_HALF_EVEN, RUBY_NUM_ROUND_HALF_UP, str, strncasecmp, SYMBOL_P, and T_STRING.

## ◆ rb_num_negative_p()

int rb_num_negative_p | ( | VALUE | num | ) |

Definition at line 319 of file numeric.c.

References num.

Referenced by rb_random_ulong_limited(), and rb_rational_pow().

## ◆ rb_num_pow()

VALUE rb_num_pow | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 4100 of file numeric.c.

References BUILTIN_TYPE, NIL_P, Qnil, rb_complex_pow(), rb_float_pow(), rb_int_pow(), rb_rational_pow(), SPECIAL_CONST_P, T_COMPLEX, and T_RATIONAL.

Referenced by rb_complex_pow().

## ◆ rb_num_to_uint()

int rb_num_to_uint | ( | VALUE | val,
|  | unsigned int * | ret
| ) |  |

Definition at line 250 of file numeric.c.

References FIX2LONG, FIXNUM_P, int(), NULL, NUMERR_NEGATIVE, NUMERR_TOOLARGE, NUMERR_TYPE, rb_absint_size(), rb_big2ulong(), and T_BIGNUM.

Referenced by rb_str_concat().

## ◆ ruby_float_mod()

double ruby_float_mod | ( | double | x,
|  | double | y
| ) |  |

Definition at line 1237 of file numeric.c.

References mod.

## ◆ ruby_float_step()

int ruby_float_step | ( | VALUE | from,
|  | VALUE | to,
|  | VALUE | step,
|  | int | excl,
|  | int | allow_endless
| ) |  |

Definition at line 2566 of file numeric.c.

References DBL2NUM, FALSE, HUGE_VAL, isinf(), NIL_P, NUM2DBL, rb_yield(), ruby_float_step_size(), T_FLOAT, and TRUE.

## ◆ ruby_float_step_size()

double ruby_float_step_size | ( | double | beg,
|  | double | end,
|  | double | unit,
|  | int | excl
| ) |  |

Definition at line 2537 of file numeric.c.

References DBL_EPSILON, err, HUGE_VAL, and isinf().

Referenced by ruby_float_step(), and ruby_num_interval_step_size().

## ◆ ruby_num_interval_step_size()

VALUE ruby_num_interval_step_size | ( | VALUE | from,
|  | VALUE | to,
|  | VALUE | step,
|  | int | excl
| ) |  |

Definition at line 2597 of file numeric.c.

References DBL2NUM, FIX2LONG, FIXNUM_P, HUGE_VAL, id_cmp, id_div, INT2FIX, isinf(), LONG2FIX, NUM2DBL, POSFIXABLE, rb_cmpint, rb_dbl2big(), rb_funcall(), rb_num_coerce_cmp(), RTEST, ruby_float_step_size(), T_FLOAT, and ULONG2NUM.