1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[DOC] rational and imaginary literals [ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-11-17 01:21:18 +00:00
parent 9d6968f1d3
commit 077a15c829

View file

@ -71,6 +71,33 @@ Examples:
All these numbers have the same decimal value, 170. Like integers and floats
you may use an underscore for readability.
=== Rational numbers
Numbers suffixed by +r+ are Rational numbers.
12r #=> (12/1)
12.3r #=> (123/10)
Rational numbers are exact, whereas Float numbers are inexact.
0.1r + 0.2r #=> (3/10)
0.1 + 0.2 #=> 0.30000000000000004
=== Complex numbers
Numbers suffixed by +i+ are Complex (or imaginary) numbers.
1i #=> (0+1i)
1i * 1i #=> (-1+0i)
Also Rational numbers may be imaginary numbers.
12.3ri #=> (0+(123/10)*i)
+i+ must be placed after +r+, the opposite is not allowed.
12.3ir #=> syntax error
== Strings
The most common way of writing strings is using <tt>"</tt>: