1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Ruby】class Rational 有理数を扱うクラスについて

Posted at
val = 1 + 1/2r
puts val.class

返ってくる値

Rational

Rationalは有理数という意味。

そもそも有理数とは、有理数とは、a/b(a、bは整数)のように分数の形に表せる数のことを言うらしい。

例えば、整数の3も3/1と表現することができるため、これも有理数を言うことができる。

val = 1 + 1/2r
この場合は、1 + 1/2 の演算となる。
すると答えは、3/2になる。

そのため、これは有理数となり、Rational(有理数)が返ってくる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?