The document discusses the future of Ruby's bigdecimal library and number system. It outlines some current problems with BigDecimal including its use of global modes, lack of automatic precision tracking, and limitations on instance generation. It suggests improvements could be made to calculation speeds by implementing more advanced algorithms. Additionally, a new class is needed to represent irrational numbers as computable algorithms rather than decimal approximations.
1 of 52
Download to read offline
More Related Content
Rubykaigi2010mrkn bigdecimal
1. bigdecimal Ruby
The future of the bigdecimal
library and the number system
of Ruby
mrkn, Kenta Murata (Genetic Lab Co., Ltd)
28. Modes in thread-local storages
? Introduced at r29099 (3 days ago)
?
Modes are maintained per-thread
?
Threads are initialized with default modes
?
Fiber safe
29. Mode conserving block
?
It makes temporary-mode-change easy
? BigDecimal.save_exception_mode { ... }
? BigDecimal.save_rounding_mode { ... }
? Introduced at r29127 (yesterday)
?
30. E?ective digits
?
The number of e?ective digits
? : 3 (three digits are e?ective)
3.141592653589792...〜100
◎
0.314 1592653589792...〜101
?
31. BigDecimal#precs
? prec[1]
The allocated length of the digit array
? prec[2]
The used length of the digit array
?
Not the number of e?ective digits
?
Do you use them?
32. BigDecimals don¨t know their own e?ective digits
? ( )
We must maintain (multiple) the number of e?ective digits
? Float
As well as Floats
?
It is too much convenient.
Should be maintained automatically.
33. Collaborate with Floats
? Float
Force converted into Floats
? Float::DIG
The number of digits is forced to Float::DIG
?
It is dangerous, don¨t mix them!
36. That is...
a = BigDecimal(^3.141592653589 ̄) # OK
b = BigDecimal(42) # NG
c = BigDecimal(Rational(355, 113)) # NG
d = BigDecimal(3.141592653589) # NG
37. That is...
a = BigDecimal(^3.141592653589 ̄) # OK
b = BigDecimal(42) # NG
c = BigDecimal(Rational(355, 113)) # NG
d = BigDecimal(3.141592653589) # NG
e = BigDecimal(a) # NG!!
38. Float is di?cult
? Float::RADIX != 10
?
Cannot convert exactly due to di?erent radix
?
Explicitly specifying the number of e?ective digits
39. Calculation speeds
?
Implemented only schoolbook multiplication
?
Implemented only schoolbook division
?
Can get more high speed