Ruby
3.4.0dev (2024-11-22 revision 80cfa57234255667a86d46096093099349a7262a)
|
Public APIs related to rb_cRational. More...
#include "ruby/internal/attr/pure.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
#include "ruby/internal/arithmetic/long.h"
Go to the source code of this file.
Macros | |
#define | rb_rational_raw1(x) rb_rational_raw((x), INT2FIX(1)) |
Shorthand of (x/1)r . More... | |
#define | rb_rational_raw2(x, y) rb_rational_raw((x), (y)) |
Just another name of rb_rational_raw. More... | |
#define | rb_rational_new1(x) rb_rational_new((x), INT2FIX(1)) |
Shorthand of (x/1)r . More... | |
#define | rb_rational_new2(x, y) rb_rational_new((x), (y)) |
Just another name of rb_rational_new. More... | |
#define | rb_Rational1(x) rb_Rational((x), INT2FIX(1)) |
Shorthand of (x/1)r . More... | |
#define | rb_Rational2(x, y) rb_Rational((x), (y)) |
Just another name of rb_Rational. More... | |
Functions | |
VALUE | rb_rational_raw (VALUE num, VALUE den) |
Identical to rb_rational_new(), except it skips argument validations. More... | |
VALUE | rb_rational_new (VALUE num, VALUE den) |
Constructs a Rational, with reduction. More... | |
VALUE | rb_Rational (VALUE num, VALUE den) |
Converts various values into a Rational. More... | |
VALUE | rb_rational_num (VALUE rat) |
Queries the numerator of the passed Rational. More... | |
VALUE | rb_rational_den (VALUE rat) |
Queries the denominator of the passed Rational. More... | |
VALUE | rb_flt_rationalize_with_prec (VALUE flt, VALUE prec) |
Simplified approximation of a float. More... | |
VALUE | rb_flt_rationalize (VALUE flt) |
Identical to rb_flt_rationalize_with_prec(), except it auto-detects appropriate precision depending on the passed value. More... | |
Public APIs related to rb_cRational.
RBIMPL
or rbimpl
are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will. __VA_ARGS__
is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98. Definition in file rational.h.
#define rb_Rational1 | ( | x | ) | rb_Rational((x), INT2FIX(1)) |
Shorthand of (x/1)r
.
It practically converts it into a Rational of the identical value.
[in] | x | rb_cInteger, rb_cRational, or something that responds to #to_r . |
(x/1)r
. Definition at line 116 of file rational.h.
#define rb_Rational2 | ( | x, | |
y | |||
) | rb_Rational((x), (y)) |
Just another name of rb_Rational.
Definition at line 119 of file rational.h.
#define rb_rational_new1 | ( | x | ) | rb_rational_new((x), INT2FIX(1)) |
Shorthand of (x/1)r
.
As x
is already an Integer, it practically converts it into a Rational of the identical value.
[in] | x | An instance of rb_cInteger. |
(x/1)r
. Definition at line 74 of file rational.h.
#define rb_rational_new2 | ( | x, | |
y | |||
) | rb_rational_new((x), (y)) |
Just another name of rb_rational_new.
Definition at line 77 of file rational.h.
#define rb_rational_raw1 | ( | x | ) | rb_rational_raw((x), INT2FIX(1)) |
Shorthand of (x/1)r
.
As x
is already an Integer, it practically converts it into a Rational of the identical value.
[in] | x | An instance of rb_cInteger. |
(x/1)r
. Definition at line 51 of file rational.h.
#define rb_rational_raw2 | ( | x, | |
y | |||
) | rb_rational_raw((x), (y)) |
Just another name of rb_rational_raw.
Definition at line 54 of file rational.h.
Identical to rb_flt_rationalize_with_prec(), except it auto-detects appropriate precision depending on the passed value.
[in] | flt | An instance of rb_cFloat to rationalise. |
flt
, in rb_cRational. Definition at line 2242 of file rational.c.
Simplified approximation of a float.
It returns a rational rat
which satisfies:
[in] | flt | An instance of rb_cFloat to rationalise. |
[in] | prec | Another rb_cFloat, which is the "precision". |
flt
, in rb_cRational. Definition at line 2226 of file rational.c.
Converts various values into a Rational.
This function accepts:
#to_r
),#to_r
),#to_r
),#to_r
.It (possibly recursively) applies #to_r
until both sides become either Integer or Rational, then divides them.
As a special case, passing RUBY_Qundef to den
is the same as passing RB_INT2NUM(1)
.
[in] | num | Numerator (see above). |
[in] | den | Denominator (see above). |
rb_eTypeError | Passed something not described above. |
rb_eFloatDomainError | #to_r produced Nan/Inf. |
rb_eZeroDivError | #to_r produced zero for den . |
(num/den)r
. Definition at line 1980 of file rational.c.
Queries the denominator of the passed Rational.
[in] | rat | An instance of rb_cRational. |
Definition at line 1995 of file rational.c.
Referenced by rb_str_format().
Constructs a Rational, with reduction.
This returns for instance (2/3)r
for rb_rational_new(INT2NUM(-384), INT2NUM(-576))
.
[in] | num | Numerator, an instance of rb_cInteger. |
[in] | den | Denominator, an instance of rb_cInteger. |
rb_eZeroDivError | den is zero. |
(num/den)r
. Definition at line 1974 of file rational.c.
Queries the numerator of the passed Rational.
[in] | rat | An instance of rb_cRational. |
Definition at line 1989 of file rational.c.
Referenced by rb_str_format().
Identical to rb_rational_new(), except it skips argument validations.
It is thus dangerous for extension libraries. For instance 1/0r
could be constructed using this.
[in] | num | Numerator, an instance of rb_cInteger. |
[in] | den | Denominator, an instance of rb_cInteger. |
rb_eTypeError | Either argument is not an Integer. |
(num/den)r
. Definition at line 1960 of file rational.c.
Referenced by rb_big_pow().