Double and precision

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Double and precision

habo
Hello

I'm having some trouble understanding the following behavior:

If I substract two doubles:
(12345.678d) - (12345.677d)  
the result is
0.0010000000002037d

Shouldn't the result be 0.001d?

Am I missing something?
Reply | Threaded
Open this post in threaded view
|

Re: Double and precision

Karsten Kusche
  i think that's the usual problem with doubles and floats:
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Kind Regards
Karsten


Am 18.08.10 08:15, schrieb habo:

> Hello
>
> I'm having some trouble understanding the following behavior:
>
> If I substract two doubles:
> (12345.678d) - (12345.677d)
> the result is
> 0.0010000000002037d
>
> Shouldn't the result be 0.001d?
>
> Am I missing something?
>

--
Karsten Kusche - Dipl. Inf. - [hidden email]
Georg Heeg eK - Köthen
Handelsregister: Amtsgericht Dortmund A 12812

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Double and precision

Boris Popov, DeepCove Labs (SNN)
In reply to this post by habo
Re: [vwnc] Double and precision

Perhaps what you're looking for is,

12345.678s - 12345.677s

?
-Boris (via BlackBerry)

----- Original Message -----
From: [hidden email] <[hidden email]>
To: habo <[hidden email]>
Cc: [hidden email] <[hidden email]>
Sent: Tue Aug 17 23:25:15 2010
Subject: Re: [vwnc] Double and precision

  i think that's the usual problem with doubles and floats:
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Kind Regards
Karsten


Am 18.08.10 08:15, schrieb habo:
> Hello
>
> I'm having some trouble understanding the following behavior:
>
> If I substract two doubles:
> (12345.678d) - (12345.677d)
> the result is
> 0.0010000000002037d
>
> Shouldn't the result be 0.001d?
>
> Am I missing something?
>

--
Karsten Kusche - Dipl. Inf. - [hidden email]
Georg Heeg eK - Köthen
Handelsregister: Amtsgericht Dortmund A 12812

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Double and precision

habo
Thank you for a quick answer.

I'm not sure I can use a FixedPoint because of the nature of the software, but I will check.
On the other hand maybe I can just "hide" the problem by using a print method with a correct printPolicy...

Regards
Habo
Reply | Threaded
Open this post in threaded view
|

Re: Double and precision

Steffen Märcker
In reply to this post by habo
Some decimal fractions with a finite representation are periodical in  
binary numeral system. As Double has limited precision these numbers  
cannot be represented completely. E.g. your numbers are
12345.678d = 12345.677734375
12345.677d = 12345.6767578125
0.001d = 0.0010000000474974513
Additionally some rounding errors occur during calculation with floating  
point numbers (float, double). It's very likely that these two effects  
lead to your result.

Regards, Steffen


Am 18.08.2010, 08:15 Uhr, schrieb habo <[hidden email]>:

>
> Hello
>
> I'm having some trouble understanding the following behavior:
>
> If I substract two doubles:
> (12345.678d) - (12345.677d)
> the result is
> 0.0010000000002037d
>
> Shouldn't the result be 0.001d?
>
> Am I missing something?
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Double and precision

Steffen Märcker
In reply to this post by habo
Another possibility would be using Fraction for all internal calculations.  
They do not suffer from side effects like floating points.

Steffen


Am 18.08.2010, 08:48 Uhr, schrieb habo <[hidden email]>:

>
> Thank you for a quick answer.
>
> I'm not sure I can use a FixedPoint because of the nature of the  
> software,
> but I will check.
> On the other hand maybe I can just "hide" the problem by using a print
> method with a correct printPolicy...
>
> Regards
> Habo
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Linux 64 bit and JUN

Jim Harsh
Hi All,

We have an application that implements a visual programming
environment to simulate and analyze radiographs. We started to use
the JUN package to create our objects. On the Windows XP boxes it
works fine, we can create an object, view it, calculate the
pathlengths of the rays passing through the object.

However Linux 64bit is another story, I changed the libraries the
JunMesaInterface was looking for to the 64 bit versions of theX11
libraries. Now I can create the object and it displays once; If I
change the Viewfinder window size, close and reopen the viewfinder,
the object isn't there.

Is there something else I have to change to get the JUN package to
work on a 64 bit Linux machine? (I using Red Hat Linux.)

Thanks

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Headless questions

Jim Harsh
I'm converting my application to run in headless mode and have a comment and question or two.

From the AppDevGuide.pdf, page 20-2

HeadlessImage default startupFilename: nil

If you do not want to use a startup file, evaluate the following
expression:

Shouldn't these two line be reversed?

Question 1, Is it possible to tell the system that the startup file will have a different name each run?

 Question 2, Do you need to specify the startup name on the command line?

I believe that if you declare a startup file name for the headless image, then you don't have to specify the name on the command line
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Headless questions

Alan Knight-2
At 12:13 PM 2010-10-27, Jim Harsh wrote:
I'm converting my application to run in headless mode and have a comment and question or two.

From the AppDevGuide.pdf, page 20-2

HeadlessImage default startupFilename: nil

If you do not want to use a startup file, evaluate the following
expression:

Shouldn't these two line be reversed?

Yes.

Question 1, Is it possible to tell the system that the startup file will have a different name each run?

You can specify it on the command line with
  -hlstrc startupFilename.st

I think it would be possible, but rather tricky, to have it be different each time in a way not specified from the command line. You'd need some piece of code to run in a subsystem that ran earlier than HeadlessImage (Load "Tools-Startup Ordering Tool" to get a browser tab that will show you the startup order when a subsystem is selected. The tricky bit is what that code would do to figure out what to change it to, and how it would make it different each time without doing something like reading from the command line.

 Question 2, Do you need to specify the startup name on the command line?

No, there's a default of "headless-startup.st"

I believe that if you declare a startup file name for the headless image, then you don't have to specify the name on the command line

Yes.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

--
Alan Knight [|], Engineering Manager, Cincom Smalltalk

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Headless questions

Jim Harsh

Thanks Alan,  I found my problem; JUN was trying to "ScheduleControllers restore" the headless image didn't like. I commented that line out and it's now working.

In the transcript the system writes out the AvailableFreeOldSpace and AvailableFreeFixedSpace mixed with some out put I'm causing. Anyway to suppress the Avail.... messges or to force a wait for my routines to avoid the mixing of the messages.

This is what the first couple of lines of the transcript file looks like.

AvailableFreeOldSpaceBytes: Filing in from:52,109,412
         -> zombie.ststarting  52,109,412October 28, 2010  
3:17:17 PM
AvailableFreeFixedSpaceBytes: GeometricObjectParameter204,800
 -> GeometricObjectParameter
401,372ConvertToUniformGrid2D
ConvertToUniformGrid2D
from here on it looks as expect it to look.

Thanks,
jim










At 01:23 PM 10/27/2010, Alan Knight wrote:
At 12:13 PM 2010-10-27, Jim Harsh wrote:
I'm converting my application to run in headless mode and have a comment and question or two.

From the AppDevGuide.pdf, page 20-2

HeadlessImage default startupFilename: nil

If you do not want to use a startup file, evaluate the following
expression:

Shouldn't these two line be reversed?

Yes.

Question 1, Is it possible to tell the system that the startup file will have a different name each run?

You can specify it on the command line with
  -hlstrc startupFilename.st

I think it would be possible, but rather tricky, to have it be different each time in a way not specified from the command line. You'd need some piece of code to run in a subsystem that ran earlier than HeadlessImage (Load "Tools-Startup Ordering Tool" to get a browser tab that will show you the startup order when a subsystem is selected. The tricky bit is what that code would do to figure out what to change it to, and how it would make it different each time without doing something like reading from the command line.

 Question 2, Do you need to specify the startup name on the command line?

No, there's a default of "headless-startup.st"

I believe that if you declare a startup file name for the headless image, then you don't have to specify the name on the command line

Yes.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

--
Alan Knight [|], Engineering Manager, Cincom Smalltalk
[hidden email]
[hidden email]
http://www.cincom.com/smalltalk

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc