the world without float literal

Post on 28-May-2015

971 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

The world without the literal notation for floating-point numbers

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

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

1Tuesday, July 19, 2011

村田賢太 (mrkn)Kenta Murata

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

CRuby Committer(BigDecimal)

Ruby Sapporo

Kosen Conf

2Tuesday, July 19, 2011

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

2010年3月1日月曜日

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

4Tuesday, July 19, 2011

札幌 Ruby 会議04

Sapporo RubyKaigi 04

Summer 2012

5Tuesday, July 19, 2011

I have some question.

6Tuesday, July 19, 2011

Do you use Float values?

7Tuesday, July 19, 2011

Do you understand Float well?

8Tuesday, July 19, 2011

Float is too difficult.

9Tuesday, July 19, 2011

Reading difficulty

10Tuesday, July 19, 2011

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

11Tuesday, July 19, 2011

Comparing difficulty

12Tuesday, July 19, 2011

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

Representation difference

14Tuesday, July 19, 2011

Human: Decimal

Internal: Binary

15Tuesday, July 19, 2011

Conceptdifference

16Tuesday, July 19, 2011

We think

Float is a number.

17Tuesday, July 19, 2011

It is real that

Float is a range.

18Tuesday, July 19, 2011

They’re troublesome

19Tuesday, July 19, 2011

There is a solution

20Tuesday, July 19, 2011

Why not use Rational.

21Tuesday, July 19, 2011

It is difficult, too.

22Tuesday, July 19, 2011

Ruby doesn’t haveany literal notations

for Rational

23Tuesday, July 19, 2011

Does a fractional notation solve the

problems?

24Tuesday, July 19, 2011

No!

25Tuesday, July 19, 2011

We naturally use decimal point notation.

26Tuesday, July 19, 2011

We need a decimal-point notation for

representing a Rational.

27Tuesday, July 19, 2011

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

Do you worry about Rational is slow?

29Tuesday, July 19, 2011

We can optimize for denominators of 10n

30Tuesday, July 19, 2011

Float isn’t as so fast as you think

31Tuesday, July 19, 2011

If you need fast Float calculation

32Tuesday, July 19, 2011

Write it in C as extension library

33Tuesday, July 19, 2011

If you need to calculate with arrays of Float

34Tuesday, July 19, 2011

Use NArray

35Tuesday, July 19, 2011

Rational may bewhat you want

36Tuesday, July 19, 2011

This talk’s background, demonstrations, and

more detail descriptions

37Tuesday, July 19, 2011

38Tuesday, July 19, 2011

top related