Unit 4. Numeral dat
2026-01-17
a = 9**10
puts a
(8*a.size).downto(0) do |n|
print a[n]
end
puts
| Rendering | \(9^{10}\) |
|---|---|
| Decimal: | 3486784401 |
| Binary: | 011001111110101000001101110010001 |
puts "|Integer | Bytes | Float render|"
puts "|:------:|:-------:|:--------:|"
40.times do |i|
a = 10**(i*10)
puts "|10^#{i*10}| #{a.size} bytes| #{a.to_f}|"
end
| Integer | Bytes | Float render |
|---|---|---|
| 10^0 | 4 bytes | 1.0 |
| 10^10 | 5 bytes | 10000000000.0 |
| 10^20 | 9 bytes | 1.0e+20 |
| 10^30 | 13 bytes | 1.0e+30 |
| 10^40 | 17 bytes | 1.0e+40 |
| 10^50 | 21 bytes | 1.0e+50 |
| 10^60 | 25 bytes | 1.0e+60 |
| 10^70 | 30 bytes | 1.0e+70 |
| 10^80 | 34 bytes | 1.0e+80 |
| 10^90 | 38 bytes | 1.0e+90 |
| 10^100 | 42 bytes | 1.0e+100 |
| 10^110 | 46 bytes | 1.0e+110 |
| 10^120 | 50 bytes | 1.0e+120 |
| 10^130 | 54 bytes | 1.0e+130 |
| 10^140 | 59 bytes | 1.0e+140 |
| 10^150 | 63 bytes | 1.0e+150 |
| 10^160 | 67 bytes | 1.0e+160 |
| 10^170 | 71 bytes | 1.0e+170 |
| 10^180 | 75 bytes | 1.0e+180 |
| 10^190 | 79 bytes | 1.0e+190 |
| 10^200 | 84 bytes | 1.0e+200 |
| 10^210 | 88 bytes | 1.0e+210 |
| 10^220 | 92 bytes | 1.0e+220 |
| 10^230 | 96 bytes | 1.0e+230 |
| 10^240 | 100 bytes | 1.0e+240 |
| 10^250 | 104 bytes | 1.0e+250 |
| 10^260 | 108 bytes | 1.0e+260 |
| 10^270 | 113 bytes | 1.0e+270 |
| 10^280 | 117 bytes | 1.0e+280 |
| 10^290 | 121 bytes | 1.0e+290 |
| 10^300 | 125 bytes | 1.0e+300 |
| 10^310 | 129 bytes | Infinity |
| 10^320 | 133 bytes | Infinity |
| 10^330 | 138 bytes | Infinity |
| 10^340 | 142 bytes | Infinity |
| 10^350 | 146 bytes | Infinity |
| 10^360 | 150 bytes | Infinity |
| 10^370 | 154 bytes | Infinity |
| 10^380 | 158 bytes | Infinity |
| 10^390 | 162 bytes | Infinity |
Float Max : 1.7976931348623157e+308 Float Min : 2.2250738585072014e-308
Float Mantissa - 53 bits
sum = 0
10_000.times do
sum = sum + 0.0001
end
print sum #=> 0.9999999999999062
require 'bigdecimal'
sum = BigDecimal("0")
10_000.times do
sum = sum + BigDecimal("0.0001")
end
print sum #=> 0.1E1
| Code | Value |
|---|---|
BigMath.PI(500).to_s |
0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065462038578883554333e1 |
Imaginary numbers
Bit operators
~ Invert bits
| : OR
& : AND
^ : XOR
<< : left shift
>> : right shift
<=> : comparison -1 , 0 , 1 - less, equal, greater
Changing Data types
.to_i : to integer.to_f : to float.to_r : to rational number.to_s : to stringfloat to integer
.floor() return to the previous integer
.round() move to the next integer if decimal >= 0.5
.ceiling() go to the next integer
IT212 Data Structure