Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Macros | Functions | Variables
rational.c File Reference
`#include "internal.h"`
`#include "id.h"`
`#include <math.h>`
`#include <float.h>`
`#include "ruby_assert.h"`
`#include <ctype.h>`

Go to the source code of this file.

## Macros
#define | NDEBUG
#define | ZERO INT2FIX(0)
#define | ONE INT2FIX(1)
#define | TWO INT2FIX(2)
#define | GMP_GCD_DIGITS 1
#define | INT_POSITIVE_P(x) (FIXNUM_P(x) ? FIXNUM_POSITIVE_P(x) : BIGNUM_POSITIVE_P(x))
#define | INT_ZERO_P(x) (FIXNUM_P(x) ? FIXNUM_ZERO_P(x) : rb_bigzero_p(x))
#define | id_idiv idDiv
#define | id_to_i idTo_i
#define | f_boolcast(x) ((x) ? Qtrue : Qfalse)
#define | f_inspect rb_inspect
#define | f_to_s rb_obj_as_string
#define | f_expt10(x) rb_int_pow(INT2FIX(10), x)
#define | f_nonzero_p(x) (!f_zero_p(x))
#define | k_exact_p(x) (!k_float_p(x))
#define | k_inexact_p(x) k_float_p(x)
#define | k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
#define | k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
#define | get_dat1(x) struct RRational *dat = RRATIONAL(x)
#define | get_dat2(x, y) struct RRational *adat = RRATIONAL(x), *bdat = RRATIONAL(y)
#define | canonicalization 0
#define | nurat_expt rb_rational_pow
#define | id_ceil rb_intern("ceil")
#define | id_quo idQuo
#define | f_reciprocal(x) f_quo(ONE, (x))
#define | id_numerator rb_intern("numerator")
#define | f_numerator(x) rb_funcall((x), id_numerator, 0)
#define | id_denominator rb_intern("denominator")
#define | f_denominator(x) rb_funcall((x), id_denominator, 0)
#define | id_to_r idTo_r
#define | f_to_r(x) rb_funcall((x), id_to_r, 0)
#define | rb_intern(str) rb_intern_const(str)

## Functions
VALUE | rb_gcd_normal (VALUE x, VALUE y)
VALUE | rb_rational_uminus (VALUE self)
VALUE | rb_rational_plus (VALUE self, VALUE other)
VALUE | rb_rational_mul (VALUE self, VALUE other)
VALUE | rb_rational_pow (VALUE self, VALUE other)
VALUE | rb_rational_cmp (VALUE self, VALUE other)
VALUE | rb_rational_abs (VALUE self)
VALUE | rb_rational_reciprocal (VALUE x)
VALUE | rb_gcd (VALUE self, VALUE other)
VALUE | rb_lcm (VALUE self, VALUE other)
VALUE | rb_gcdlcm (VALUE self, VALUE other)
VALUE | rb_rational_raw (VALUE x, VALUE y)
VALUE | rb_rational_new (VALUE x, VALUE y)
VALUE | rb_Rational (VALUE x, VALUE y)
VALUE | rb_rational_num (VALUE rat)
VALUE | rb_rational_den (VALUE rat)
VALUE | rb_numeric_quo (VALUE x, VALUE y)
VALUE | rb_rational_canonicalize (VALUE x)
VALUE | rb_float_numerator (VALUE self)
VALUE | rb_float_denominator (VALUE self)
VALUE | rb_flt_rationalize_with_prec (VALUE flt, VALUE prec)
VALUE | rb_flt_rationalize (VALUE flt)
VALUE | rb_cstr_to_rat (const char *s, int strict)
void | Init_Rational (void)

## Variables
VALUE | rb_cRational

## Macro Definition Documentation

## ◆ canonicalization

#define canonicalization 0

Definition at line 425 of file rational.c.

## ◆ f_boolcast

#define f_boolcast | ( |  | x | ) | ((x) ? Qtrue : Qfalse)

Definition at line 42 of file rational.c.

## ◆ f_denominator

#define f_denominator | ( |  | x | ) | rb_funcall((x), id_denominator, 0)

Definition at line 1975 of file rational.c.

## ◆ f_expt10

#define f_expt10 | ( |  | x | ) | rb_int_pow(INT2FIX(10), x)

Definition at line 148 of file rational.c.

## ◆ f_inspect

#define f_inspect rb_inspect

Definition at line 43 of file rational.c.

## ◆ f_nonzero_p

#define f_nonzero_p | ( |  | x | ) | (!f_zero_p(x))

Definition at line 164 of file rational.c.

## ◆ f_numerator

#define f_numerator | ( |  | x | ) | rb_funcall((x), id_numerator, 0)

Definition at line 1972 of file rational.c.

## ◆ f_reciprocal

#define f_reciprocal | ( |  | x | ) | f_quo(ONE, (x))

Definition at line 1618 of file rational.c.

## ◆ f_to_r

#define f_to_r | ( |  | x | ) | rb_funcall((x), id_to_r, 0)

Definition at line 1978 of file rational.c.

## ◆ f_to_s

#define f_to_s rb_obj_as_string

Definition at line 44 of file rational.c.

## ◆ get_dat1

#define get_dat1 | ( |  | x | ) | struct RRational *dat = RRATIONAL(x)

Definition at line 386 of file rational.c.

## ◆ get_dat2

#define get_dat2 | ( |  | x,
|  |  | y
| ) |  | struct RRational *adat = RRATIONAL(x), *bdat = RRATIONAL(y)

Definition at line 389 of file rational.c.

## ◆ GMP_GCD_DIGITS

#define GMP_GCD_DIGITS 1

Definition at line 29 of file rational.c.

## ◆ id_ceil

#define id_ceil rb_intern("ceil")

Definition at line 1594 of file rational.c.

## ◆ id_denominator

#define id_denominator rb_intern("denominator")

Definition at line 1974 of file rational.c.

## ◆ id_idiv

#define id_idiv idDiv

Definition at line 39 of file rational.c.

## ◆ id_numerator

#define id_numerator rb_intern("numerator")

Definition at line 1971 of file rational.c.

## ◆ id_quo

#define id_quo idQuo

Definition at line 1606 of file rational.c.

## ◆ id_to_i

#define id_to_i idTo_i

Definition at line 40 of file rational.c.

## ◆ id_to_r

#define id_to_r idTo_r

Definition at line 1977 of file rational.c.

## ◆ INT_POSITIVE_P

#define INT_POSITIVE_P | ( |  | x | ) | (FIXNUM_P(x) ? FIXNUM_POSITIVE_P(x) : BIGNUM_POSITIVE_P(x))

Definition at line 31 of file rational.c.

## ◆ INT_ZERO_P

#define INT_ZERO_P | ( |  | x | ) | (FIXNUM_P(x) ? FIXNUM_ZERO_P(x) : rb_bigzero_p(x))

Definition at line 32 of file rational.c.

## ◆ k_exact_one_p

#define k_exact_one_p | ( |  | x | ) | (k_exact_p(x) && f_one_p(x))

Definition at line 233 of file rational.c.

## ◆ k_exact_p

#define k_exact_p | ( |  | x | ) | (!k_float_p(x))

Definition at line 229 of file rational.c.

## ◆ k_exact_zero_p

#define k_exact_zero_p | ( |  | x | ) | (k_exact_p(x) && f_zero_p(x))

Definition at line 232 of file rational.c.

## ◆ k_inexact_p

#define k_inexact_p | ( |  | x | ) | k_float_p(x)

Definition at line 230 of file rational.c.

## ◆ NDEBUG

#define NDEBUG

Definition at line 17 of file rational.c.

## ◆ nurat_expt

#define nurat_expt rb_rational_pow

Definition at line 1077 of file rational.c.

## ◆ ONE

#define ONE INT2FIX(1)

Definition at line 26 of file rational.c.

## ◆ rb_intern

#define rb_intern | ( |  | str | ) | rb_intern_const(str)

## ◆ TWO

#define TWO INT2FIX(2)

Definition at line 27 of file rational.c.

## ◆ ZERO

#define ZERO INT2FIX(0)

Definition at line 25 of file rational.c.

## Function Documentation

## ◆ Init_Rational()

void Init_Rational | ( | void |  | ) |

Definition at line 2712 of file rational.c.

## ◆ rb_cstr_to_rat()

VALUE rb_cstr_to_rat | ( | const char * | s,
|  | int | strict
| ) |  |

Definition at line 2541 of file rational.c.

## ◆ rb_float_denominator()

VALUE rb_float_denominator | ( | VALUE | self | ) |

Definition at line 2104 of file rational.c.

References INT2FIX, isinf, isnan, and RFLOAT_VALUE.

## ◆ rb_float_numerator()

VALUE rb_float_numerator | ( | VALUE | self | ) |

Definition at line 2081 of file rational.c.

References isinf, isnan, and RFLOAT_VALUE.

## ◆ rb_flt_rationalize()

VALUE rb_flt_rationalize | ( | VALUE | flt | ) |

Definition at line 2242 of file rational.c.

References f, and n.

## ◆ rb_flt_rationalize_with_prec()

VALUE rb_flt_rationalize_with_prec | ( | VALUE | flt,
|  | VALUE | prec
| ) |  |

Definition at line 2226 of file rational.c.

References f_abs.

## ◆ rb_gcd()

VALUE rb_gcd | ( | VALUE | self,
|  | VALUE | other
| ) |  |

Definition at line 1894 of file rational.c.

Referenced by rb_int_fdiv_double().

## ◆ rb_gcd_normal()

VALUE rb_gcd_normal | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 344 of file rational.c.

## ◆ rb_gcdlcm()

VALUE rb_gcdlcm | ( | VALUE | self,
|  | VALUE | other
| ) |  |

Definition at line 1932 of file rational.c.

## ◆ rb_lcm()

VALUE rb_lcm | ( | VALUE | self,
|  | VALUE | other
| ) |  |

Definition at line 1913 of file rational.c.

## ◆ rb_numeric_quo()

VALUE rb_numeric_quo | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 2014 of file rational.c.

References canonicalization, idFdiv, rb_complex_div(), rb_convert_type(), RB_FLOAT_TYPE_P, rb_funcallv, rb_rational_raw1, RB_TYPE_P, T_COMPLEX, and T_RATIONAL.

Referenced by fun2().

## ◆ rb_Rational()

VALUE rb_Rational | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1951 of file rational.c.

## ◆ rb_rational_abs()

VALUE rb_rational_abs | ( | VALUE | self | ) |

Definition at line 1255 of file rational.c.

References get_dat1, INT_NEGATIVE_P, and rb_int_abs().

## ◆ rb_rational_canonicalize()

VALUE rb_rational_canonicalize | ( | VALUE | x | ) |

Definition at line 2034 of file rational.c.

References get_dat1, RB_TYPE_P, and T_RATIONAL.

## ◆ rb_rational_cmp()

VALUE rb_rational_cmp | ( | VALUE | self,
|  | VALUE | other
| ) |  |

Definition at line 1097 of file rational.c.

References get_dat1, LONG2FIX, rb_int_cmp(), and RB_INTEGER_TYPE_P.

## ◆ rb_rational_den()

VALUE rb_rational_den | ( | VALUE | rat | ) |

Definition at line 1966 of file rational.c.

## ◆ rb_rational_mul()

VALUE rb_rational_mul | ( | VALUE | self,
|  | VALUE | other
| ) |  |

Definition at line 874 of file rational.c.

References get_dat1, and RB_INTEGER_TYPE_P.

## ◆ rb_rational_new()

VALUE rb_rational_new | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1945 of file rational.c.

## ◆ rb_rational_num()

VALUE rb_rational_num | ( | VALUE | rat | ) |

Definition at line 1960 of file rational.c.

## ◆ rb_rational_plus()

VALUE rb_rational_plus | ( | VALUE | self,
|  | VALUE | other
| ) |  |

Definition at line 737 of file rational.c.

References get_dat1, and RB_INTEGER_TYPE_P.

## ◆ rb_rational_pow()

VALUE rb_rational_pow | ( | VALUE | self,
|  | VALUE | other
| ) |  |

Definition at line 1002 of file rational.c.

Referenced by rb_num_pow().

## ◆ rb_rational_raw()

VALUE rb_rational_raw | ( | VALUE | x,
|  | VALUE | y
| ) |  |

Definition at line 1939 of file rational.c.

## ◆ rb_rational_reciprocal()

VALUE rb_rational_reciprocal | ( | VALUE | x | ) |

Definition at line 1875 of file rational.c.

References get_dat1.

## ◆ rb_rational_uminus()

VALUE rb_rational_uminus | ( | VALUE | self | ) |

Definition at line 624 of file rational.c.

References assert, get_dat1, RB_TYPE_P, T_RATIONAL, and void.