the world without the literal notation for floating-point numbers

38
The world without the literal notation for floating-point numbers 村田賢太, Kenta Murata GeneticLab Co., Ltd. 浮動小数点数リテラルが無い世界 1 Tuesday, July 19, 2011

Upload: kenta-murata

Post on 20-Jan-2015

1.419 views

Category:

Technology


0 download

DESCRIPTION

We need the decimal-point literal notation for Rational instead of Float because Float is legacy.

TRANSCRIPT

Page 1: The world without the literal notation for floating-point numbers

The world without the literal notation for floating-point numbers

村田賢太, Kenta MurataGeneticLab Co., Ltd.

浮動小数点数リテラルが無い世界

1Tuesday, July 19, 2011

Page 2: The world without the literal notation for floating-point numbers

村田賢太 (mrkn)Kenta Murata

http://www.flickr.com/photos/koichiroo/5244581973/

CRuby Committer(BigDecimal)

Ruby Sapporo

Kosen Conf

2Tuesday, July 19, 2011

Page 3: The world without the literal notation for floating-point numbers

2010年3月1日月曜日 3Tuesday, July 19, 2011

Page 4: The world without the literal notation for floating-point numbers

2010年3月1日月曜日

ジュンク堂 RubyKaigi 支店残り n 冊!!

4Tuesday, July 19, 2011

Page 5: The world without the literal notation for floating-point numbers

札幌 Ruby 会議04

Sapporo RubyKaigi 04

Summer 2012

5Tuesday, July 19, 2011

Page 6: The world without the literal notation for floating-point numbers

I have some question.

6Tuesday, July 19, 2011

Page 7: The world without the literal notation for floating-point numbers

Do you use Float values?

7Tuesday, July 19, 2011

Page 8: The world without the literal notation for floating-point numbers

Do you understand Float well?

8Tuesday, July 19, 2011

Page 9: The world without the literal notation for floating-point numbers

Float is too difficult.

9Tuesday, July 19, 2011

Page 10: The world without the literal notation for floating-point numbers

Reading difficulty

10Tuesday, July 19, 2011

Page 11: The world without the literal notation for floating-point numbers

ruby-1.9.2-p290 :001 > 76287755398823936.0 => 76287755398823940.0 ruby-1.9.2-p290 :002 >

11Tuesday, July 19, 2011

Page 12: The world without the literal notation for floating-point numbers

Comparing difficulty

12Tuesday, July 19, 2011

Page 13: The world without the literal notation for floating-point numbers

ruby-1.9.2-p290 :001 > 12.4 * 1.05 == 13.02 => false

ruby-1.9.2-p290 :002 > 12.4 * 1.05 => 13.020000000000001 ruby-1.9.2-p290 :003 >

13Tuesday, July 19, 2011

Page 14: The world without the literal notation for floating-point numbers

Representation difference

14Tuesday, July 19, 2011

Page 15: The world without the literal notation for floating-point numbers

Human: Decimal

Internal: Binary

15Tuesday, July 19, 2011

Page 16: The world without the literal notation for floating-point numbers

Conceptdifference

16Tuesday, July 19, 2011

Page 17: The world without the literal notation for floating-point numbers

We think

Float is a number.

17Tuesday, July 19, 2011

Page 18: The world without the literal notation for floating-point numbers

It is real that

Float is a range.

18Tuesday, July 19, 2011

Page 19: The world without the literal notation for floating-point numbers

They’re troublesome

19Tuesday, July 19, 2011

Page 20: The world without the literal notation for floating-point numbers

There is a solution

20Tuesday, July 19, 2011

Page 21: The world without the literal notation for floating-point numbers

Why not use Rational.

21Tuesday, July 19, 2011

Page 22: The world without the literal notation for floating-point numbers

It is difficult, too.

22Tuesday, July 19, 2011

Page 23: The world without the literal notation for floating-point numbers

Ruby doesn’t haveany literal notations

for Rational

23Tuesday, July 19, 2011

Page 24: The world without the literal notation for floating-point numbers

Does a fractional notation solve the

problems?

24Tuesday, July 19, 2011

Page 25: The world without the literal notation for floating-point numbers

No!

25Tuesday, July 19, 2011

Page 26: The world without the literal notation for floating-point numbers

We naturally use decimal point notation.

26Tuesday, July 19, 2011

Page 27: The world without the literal notation for floating-point numbers

We need a decimal-point notation for

representing a Rational.

27Tuesday, July 19, 2011

Page 28: The world without the literal notation for floating-point numbers

ruby--p290 :001 > 13.02.class => Rational

ruby--p290 :001 > 12.4 * 1.05 == 13.02 => true

ruby-1.9.2-p290 :002 > 12.4 * 1.05 => 13.02

ruby-1.9.2-p290 :003 > 13.02 / 3 => (217/50)

28Tuesday, July 19, 2011

Page 29: The world without the literal notation for floating-point numbers

Do you worry about Rational is slow?

29Tuesday, July 19, 2011

Page 30: The world without the literal notation for floating-point numbers

We can optimize for denominators of 10n

30Tuesday, July 19, 2011

Page 31: The world without the literal notation for floating-point numbers

Float isn’t as so fast as you think

31Tuesday, July 19, 2011

Page 32: The world without the literal notation for floating-point numbers

If you need fast Float calculation

32Tuesday, July 19, 2011

Page 33: The world without the literal notation for floating-point numbers

Write it in C as extension library

33Tuesday, July 19, 2011

Page 34: The world without the literal notation for floating-point numbers

If you need to calculate with arrays of Float

34Tuesday, July 19, 2011

Page 35: The world without the literal notation for floating-point numbers

Use NArray

35Tuesday, July 19, 2011

Page 36: The world without the literal notation for floating-point numbers

Rational may bewhat you want

36Tuesday, July 19, 2011

Page 37: The world without the literal notation for floating-point numbers

This talk’s background, demonstrations, and

more detail descriptions

37Tuesday, July 19, 2011

Page 38: The world without the literal notation for floating-point numbers

38Tuesday, July 19, 2011