D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Rational
/
Filename :
cdesc-Rational.ri
back
Copy
U:RDoc::NormalClass[iI" Rational:ET@I"Numeric;To:RDoc::Markup::Document:@parts[o;;[ : @fileI"&ext/json/lib/json/add/rational.rb;T:0@omit_headings_from_table_of_contents_below0o;;[o:RDoc::Markup::Paragraph;[I"HA rational number can be represented as a pair of integer numbers: ;TI"Ca/b (b>0), where a is the numerator and b is the denominator. ;TI"2Integer a equals rational a/1 mathematically.;To:RDoc::Markup::BlankLine o;;[I"7You can create a \Rational object explicitly with:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o;;[I"KA {rational literal}[rdoc-ref:syntax/literals.rdoc@Rational+Literals].;T@o;;[I"7You can convert certain objects to Rationals with:;T@o; ;;;[o;;0;[o;;[I"\Method #Rational.;T@o;;[I" Examples;T@o:RDoc::Markup::Verbatim;[ I" Rational(1) #=> (1/1) ;TI" Rational(2, 3) #=> (2/3) ;TI",Rational(4, -6) #=> (-2/3) # Reduced. ;TI" 3.to_r #=> (3/1) ;TI" 2/3r #=> (2/3) ;T:@format0o;;[I"IYou can also create rational objects from floating-point numbers or ;TI" strings.;T@o;;[ I"?Rational(0.3) #=> (5404319552844595/18014398509481984) ;TI"!Rational('0.3') #=> (3/10) ;TI" Rational('2/3') #=> (2/3) ;TI" ;TI"?0.3.to_r #=> (5404319552844595/18014398509481984) ;TI"!'0.3'.to_r #=> (3/10) ;TI" '2/3'.to_r #=> (2/3) ;TI"!0.3.rationalize #=> (3/10) ;T;0o;;[I"DA rational object is an exact number, which helps you to write ;TI"*programs without any rounding errors.;T@o;;[I"K10.times.inject(0) {|t| t + 0.1 } #=> 0.9999999999999999 ;TI">10.times.inject(0) {|t| t + Rational('0.1') } #=> (1/1) ;T;0o;;[I"PHowever, when an expression includes an inexact component (numerical value ;TI"6or operation), it will produce an inexact result.;T@o;;[ I"#Rational(10) / 3 #=> (10/3) ;TI"/Rational(10) / 3.0 #=> 3.3333333333333335 ;TI" ;TI"$Rational(-8) ** Rational(1, 3) ;TI"D #=> (1.0000000000000002+1.7320508075688772i);T;0; I"rational.c;T; 0; 0; 0[ [ [ [[I" class;T[[:public[[I"json_create;TI"&ext/json/lib/json/add/rational.rb;T[:protected[ [:private[ [I" instance;T[[;["[I"*;TI"rational.c;T[I"**;T@m[I"+;T@m[I"-;T@m[I"-@;T@m[I"/;T@m[I"<=>;T@m[I"==;T@m[I"abs;T@m[I"as_json;T@a[I" ceil;T@m[I"denominator;T@m[I" fdiv;T@m[I" floor;T@m[I" hash;T@m[I"inspect;T@m[I"magnitude;T@m[I"negative?;T@m[I"numerator;T@m[I"positive?;T@m[I"quo;T@m[I"rationalize;T@m[I" round;T@m[I" to_f;T@m[I" to_i;T@m[I"to_json;T@a[I" to_r;T@m[I" to_s;T@m[I" truncate;T@m[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ; 0; 0[@ @U@UcRDoc::TopLevel