ruby-changes:53557
From: nobu <ko1@a...>
Date: Sat, 17 Nov 2018 10:21:23 +0900 (JST)
Subject: [ruby-changes:53557] nobu:r65773 (trunk): [DOC] rational and imaginary literals [ci skip]
nobu 2018-11-17 10:21:18 +0900 (Sat, 17 Nov 2018) New Revision: 65773 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65773 Log: [DOC] rational and imaginary literals [ci skip] Modified files: trunk/doc/syntax/literals.rdoc Index: doc/syntax/literals.rdoc =================================================================== --- doc/syntax/literals.rdoc (revision 65772) +++ doc/syntax/literals.rdoc (revision 65773) @@ -71,6 +71,33 @@ Examples: https://github.com/ruby/ruby/blob/trunk/doc/syntax/literals.rdoc#L71 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>: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/