Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: rounding pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 25 of 36 Topic 15511 of 17437
Post > Topic >>

Re: rounding problems

by justin@[EMAIL PROTECTED] (Justin) May 14, 2008 at 11:47 AM

This is a multi-part message in MIME format.
--------------040903080603000607070801
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I have forgotten how much i hate C++

Its not doing what you say it would but it did do other odd ball 
things.  I miss my foxpro :-(. 

Plus its not holding 15 precision points

#include <stdio.h>
#include <cmath>

int main()
{
        double a = 0.1;
        //double b = 1000;
        double c = 100000000;
        double d ; //= a * b;
        for( int i = 1 ; i < 10 ; i++)
        {   
            d = pow(a,i)+ c ;
            printf("%.10f\n", d);
            d = d-c ;
            printf("%.10f\n", d);
        }

        return 0;
}

Sam Mason wrote:
> On Tue, May 13, 2008 at 02:36:18PM -0400, Justin wrote:
>   
>> Double holds 15 places which is the highest value of precision it can 
>> maintain before rounding occurs.
>>
>> Is is limit less no, but what is?
>>
>> Practically speaking  taking a vale 0.000,000,000,000,001 aka
>> 1 trillionth of anything,
>>     
>
> But remember that if you add this value onto a large number and then
> take off the large number the result will be zero.
>
>   (0.000,000,000,01 + 1,000,000) - 1,000,000  ==>  0
>   0.000,000,000,01 + (1,000,000 - 1,000,000)  ==>  0.000,000,000,01
>
> In general, operations on floating point numbers will increase their
> errors.
>
>   
>> i view the problem solved for 98% of problems.
>>     
>
> Floating point math is good for most problems, hence why most languages
> expose the abstraction.
>
>
>   Sam
>
>   

--------------040903080603000607070801
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I have forgotten how much i hate C++<br>
<br>
Its not doing what you say it would but it did do other odd ball
things.&nbsp; I miss my foxpro :-(.&nbsp; <br>
<br>
Plus its not holding 15 precision points<br>
<br>
#include &lt;stdio.h&gt;<br>
#include &lt;cmath&gt;<br>
<br>
int main()<br>
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double a = 0.1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //double b = 1000;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double c = 100000000;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double d ; //= a * b;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for( int i = 1 ; i &lt; 10 ;
i++)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; d = pow(a,i)+ c
;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("%.10f\n",
d);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; d = d-c ;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf("%.10f\n",
d);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>
}<br>
<br>
Sam Mason wrote:
<blockquote
 cite="mid:20080514143817.GF1657@[EMAIL PROTECTED]
"
 type="cite">
  <pre wrap="">On Tue, May 13, 2008 at 02:36:18PM -0400, Justin wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Double holds 15 places which is the highest value of
precision it can 
maintain before rounding occurs.

Is is limit less no, but what is?

Practically speaking  taking a vale 0.000,000,000,000,001 aka
1 trillionth of anything,
    </pre>
  </blockquote>
  <pre wrap=""><!---->
But remember that if you add this value onto a large number and then
take off the large number the result will be zero.

  (0.000,000,000,01 + 1,000,000) - 1,000,000  ==&gt;  0
  0.000,000,000,01 + (1,000,000 - 1,000,000)  ==&gt;  0.000,000,000,01

In general, operations on floating point numbers will increase their
errors.

  </pre>
  <blockquote type="cite">
    <pre wrap="">i view the problem solved for 98% of problems.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Floating point math is good for most problems, hence why most languages
expose the abstraction.


  Sam

  </pre>
</blockquote>
</body>
</html>

--------------040903080603000607070801--
 




 36 Posts in Topic:
rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 13:48:16 
Re: rounding problems
lyeoh@[EMAIL PROTECTED]   2008-05-13 02:07:09 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 14:54:47 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 15:08:11 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 04:29:06 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:02:30 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:09:57 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 17:23:15 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 05:50:16 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 18:37:02 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 19:04:13 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-13 02:20:18 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 22:51:42 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 11:42:09 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 00:16:06 
Re: rounding problems
xof@[EMAIL PROTECTED] (C  2008-05-12 14:53:21 
Re: rounding problems
craig@[EMAIL PROTECTED]   2008-05-13 05:26:46 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 14:18:57 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-12 14:49:48 
Re: rounding problems
tometzky@[EMAIL PROTECTED  2008-05-13 08:40:41 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 11:30:48 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 13:29:07 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 14:36:18 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 15:38:17 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 11:47:52 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 17:26:30 
Re: rounding problems
sam@[EMAIL PROTECTED] (S  2008-05-14 20:27:19 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-14 16:02:32 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 16:08:54 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-14 16:24:58 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-14 16:55:49 
Re: rounding problems
glene77is <glen.e77is@  2008-05-20 03:19:20 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-20 10:28:28 
Re: rounding problems
aanderson@[EMAIL PROTECTE  2008-05-12 15:56:30 
Re: rounding problems
justin@[EMAIL PROTECTED]   2008-05-13 13:01:11 
Re: rounding problems
doug@[EMAIL PROTECTED] (  2008-05-13 12:12:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 13:05:26 CST 2008.