Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. How to improve the accuracy of floating point calculation?
(yi lu)
2. Re: How to improve the accuracy of floating point
calculation? (Brandon Allbery)
3. Re: How to improve the accuracy of floating point
calculation? (Hollister Herhold)
4. Re: How to improve the accuracy of floating point
calculation? (David McBride)
5. Re: How to improve the accuracy of floating point
calculation? (yi lu)
6. Re: How to improve the accuracy of floating point
calculation? (KC)
----------------------------------------------------------------------
Message: 1
Date: Wed, 6 Feb 2013 06:41:17 +0800
From: yi lu <[email protected]>
Subject: [Haskell-beginners] How to improve the accuracy of floating
point calculation?
To: [email protected]
Message-ID:
<CAKcmqqxr7W9S1FP=ebykgaxdzzbcaa5lu0h7eec-y0atyn2...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I found that in ghci, I input
[0.1,0.2..2]
and run, I get a result of
[0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
But, as you know, it is not the exact answer.
So, I wonder if there is something I can do to achieve a better performance
and get [0.1,0.2,0.3,0.4..] as the result.
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130206/cc008345/attachment-0001.htm>
------------------------------
Message: 2
Date: Tue, 5 Feb 2013 17:50:59 -0500
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAKFCL4WAxUwjvfNjEmTAeZ-hDN=hnrchdm+jxobetxrevnp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Tue, Feb 5, 2013 at 5:41 PM, yi lu <[email protected]> wrote:
> I found that in ghci, I input
> [0.1,0.2..2]
> and run, I get a result of
>
>
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
>
> But, as you know, it is not the exact answer.
>
> So, I wonder if there is something I can do to achieve a better
> performance and get [0.1,0.2,0.3,0.4..] as the result.
>
Welcome to the world of floating point numbers. Perfect accuracy is not
possible; the CReal type from the "numbers" package may handle cases you
care about, or may not. (Other languages often use output formats that can
largely hide the errors, but they're still there and will eventually
accumulate into visibility.)
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130205/2357eb94/attachment-0001.htm>
------------------------------
Message: 3
Date: Tue, 5 Feb 2013 16:52:34 -0600
From: Hollister Herhold <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
The issue is that floating point numbers are really not precise.
This is not inherent to Haskell in particular - any given computer (and
programming language) is subject to lack of precision for floating point
numbers. You can take a look at the wikipedia entry
(http://en.wikipedia.org/wiki/Floating_point_numbers).
If you want a really "meaty" description of the issues involved, take a look at
Knuth's "Seminumerical Algorithms".
On Feb 5, 2013, at 4:41 PM, yi lu wrote:
> Hi,
>
> I found that in ghci, I input
> [0.1,0.2..2]
> and run, I get a result of
>
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
>
> But, as you know, it is not the exact answer.
>
> So, I wonder if there is something I can do to achieve a better performance
> and get [0.1,0.2,0.3,0.4..] as the result.
>
> Thanks.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 4
Date: Tue, 5 Feb 2013 17:55:52 -0500
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAN+Tr40X0m=k_cbfe7gttjuipmqauvrkgymcopubwnfkeyv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Use rationals and then convert to float. Ie:
> [0.1::Rational,0.2..2]
[1 % 10,1 % 5,3 % 10,2 % 5,1 % 2,3 % 5,7 % 10,4 % 5,9 % 10,1 % 1,11 % 10,6
% 5,13 % 10,7 % 5,3 % 2,8 % 5,17 % 10,9 % 5,19 % 10,2 % 1]
Then to get something useful from it:
> map fromRational $ [0.1::Rational,0.2..2]
[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0]
On Tue, Feb 5, 2013 at 5:41 PM, yi lu <[email protected]> wrote:
> Hi,
>
> I found that in ghci, I input
> [0.1,0.2..2]
> and run, I get a result of
>
>
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
>
> But, as you know, it is not the exact answer.
>
> So, I wonder if there is something I can do to achieve a better
> performance and get [0.1,0.2,0.3,0.4..] as the result.
>
> Thanks.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130205/5bb5d75a/attachment-0001.htm>
------------------------------
Message: 5
Date: Wed, 6 Feb 2013 07:04:06 +0800
From: yi lu <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAKcmqqy3SrQa1wyMzyUW5==npd1wxqxjod5f1cl4eaba5ya...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thanks!
I'll try CReal.
But can I set *significant figures **myself?*
On Wed, Feb 6, 2013 at 6:50 AM, Brandon Allbery <[email protected]> wrote:
> On Tue, Feb 5, 2013 at 5:41 PM, yi lu <[email protected]>wrote:
>
>> I found that in ghci, I input
>> [0.1,0.2..2]
>> and run, I get a result of
>>
>>
>> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
>>
>> But, as you know, it is not the exact answer.
>>
>> So, I wonder if there is something I can do to achieve a better
>> performance and get [0.1,0.2,0.3,0.4..] as the result.
>>
>
> Welcome to the world of floating point numbers. Perfect accuracy is not
> possible; the CReal type from the "numbers" package may handle cases you
> care about, or may not. (Other languages often use output formats that can
> largely hide the errors, but they're still there and will eventually
> accumulate into visibility.)
>
> --
> brandon s allbery kf8nh sine nomine
> associates
> [email protected]
> [email protected]
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130206/49d6437c/attachment-0001.htm>
------------------------------
Message: 6
Date: Tue, 5 Feb 2013 15:08:43 -0800
From: KC <[email protected]>
Subject: Re: [Haskell-beginners] How to improve the accuracy of
floating point calculation?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<camlkxyn+5m4bi6whmgbcaoq6wk4cg03u3msf8o12913bru8...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
0.1 cannot be represented exactly in floating point.
0.5 can be represented exactly. Why?
On Tue, Feb 5, 2013 at 2:41 PM, yi lu <[email protected]> wrote:
> Hi,
>
> I found that in ghci, I input
> [0.1,0.2..2]
> and run, I get a result of
>
> [0.1,0.2,0.30000000000000004,0.4000000000000001,0.5000000000000001,0.6000000000000001,0.7000000000000001,0.8,0.9,1.0,1.1,1.2000000000000002,1.3000000000000003,1.4000000000000004,1.5000000000000004,1.6000000000000005,1.7000000000000006,1.8000000000000007,1.9000000000000008,2.000000000000001]
>
> But, as you know, it is not the exact answer.
>
> So, I wonder if there is something I can do to achieve a better performance
> and get [0.1,0.2,0.3,0.4..] as the result.
>
> Thanks.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
--
Regards,
KC
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 56, Issue 9
****************************************