Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Jan 16, 2013 8:42 am 
Offline

Joined: Wed Jan 16, 2013 8:27 am
Posts: 1
I expected 0.3

?


Top
   
PostPosted: Wed Jan 16, 2013 8:47 am 
Offline
Senior Member

Joined: Mon Aug 29, 2011 2:34 am
Posts: 77
dragolov wrote:
I expected 0.3

?


Welcome to IEEE 754 double-precision floating point arithmetic. http://en.wikipedia.org/wiki/IEEE_floating_point Basic gist is don't expect anything to ever be exact :) .


Top
   
PostPosted: Wed Jan 16, 2013 11:30 am 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
It's been a long time since I touched Haskell in university, but in most languages, I'd say "Don't use double if you need a precise answer, use the language's decimal implementation."


Top
   
PostPosted: Wed Jan 16, 2013 1:55 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
Curiously,

Code:
Python 2.6.5 (r265:79063, Oct  1 2012, 22:04:36) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 9.3 - (2 * 4.5)
0.30000000000000071

$ irb -v
irb 0.9.5(05/04/13)
$ irb
irb(main):001:0> 9.3 - (2 * 4.5)
=> 0.300000000000001

$ perl -v

This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
...
$ perl -e "print 9.3 - (2 * 4.5);"
0.300000000000001

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
PostPosted: Thu Jan 17, 2013 9:01 am 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
Code:
$ bc -v
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
$ echo 'scale=100; 9.3 - (2 * 4.5)' | bc
.3


:)


Top
   
PostPosted: Thu Jan 17, 2013 9:18 am 
Offline
Senior Member

Joined: Fri Feb 18, 2005 4:09 pm
Posts: 594
IIRC the latest version of Haskell now makes all internal calculations using Roman numerals instead of binary, negating this problem.

James


Top
   
PostPosted: Thu Jan 17, 2013 11:40 am 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
That sounds about right for Haskell.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group