From 077a15c829f36357b2452d54adaf95ff5c7698f8 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 17 Nov 2018 01:21:18 +0000 Subject: [PATCH] [DOC] rational and imaginary literals [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- doc/syntax/literals.rdoc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/syntax/literals.rdoc b/doc/syntax/literals.rdoc index b8ed7f7c54..62b80db04b 100644 --- a/doc/syntax/literals.rdoc +++ b/doc/syntax/literals.rdoc @@ -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 ":