diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-17 01:21:18 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-17 01:21:18 +0000 |
commit | 077a15c829f36357b2452d54adaf95ff5c7698f8 (patch) | |
tree | e21d417d51c4494a0cc2fe898b46cebe0e52584c /doc/syntax | |
parent | 9d6968f1d3ae7bb875abda6eaf25189e4bc371fc (diff) |
[DOC] rational and imaginary literals [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'doc/syntax')
-rw-r--r-- | doc/syntax/literals.rdoc | 27 |
1 files changed, 27 insertions, 0 deletions
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 <tt>"</tt>: |