> For the complete documentation index, see [llms.txt](https://huang-jason.gitbook.io/ruby-rails-syntax/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://huang-jason.gitbook.io/ruby-rails-syntax/chap_3.md).

# chap 3

## Number

```
Numeric
  |-Integer
      |-Fixnum
      |-Bignum
  |-Float
  |-Complex
  |-Rational
  |-BigDecimal (Standard Library)
```

```
$ Fixnum.ancestors
=> [Fixnum, Integer, Numeric, Comparable, Object, Kernel, BasicObject]

$ Fixnum.included_modules
=> [Comparable, Kernel]
```

| Type       |                     | ex           |
| ---------- | ------------------- | ------------ |
| Fixnum     |                     | 1            |
| Bignum     |                     | 111111111111 |
| Float      | Imprecise           | 5.0          |
| BigDecimal | precise             | 3.0          |
| Complex    | imaginary numbers   | (1+0i)       |
| Rational   | represent fractions | (2/3)        |

## Float vs BigDecimal (precision)

```ruby
0.2 + 0.1 == 0.3
# false

require 'bigdecimal'
BigDecimal("0.2") + BigDecimal("0.1") == 0.3
# true
```

`BigDecimal` is 12 times slower than `Float`

## Fixnum vs Bignum

```ruby
1.class
# Fixnum

100000000000.class
# Bignum
```

```ruby
1.object_id
# 3
1.object_id # id is not changed
# 3 

9999999999999999999999999999999999.object_id
# 70225433369420
9999999999999999999999999999999999.object_id # id is changed
# 70225433617420
```

**Fixnum** like symbols in the interpreter level.

**Bignum** normal class & uses normal object ids.
