Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 9:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Code: 5.55112e-017 instead of 0
PostPosted: June 21st, 2010, 11:16 am 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
Am I doing something really silly here. Please tell me I am, as I keep get a very odd answer.

I keep getting 5.55112e-017 instead of 0

Page variable called TestVarMe set to the number 1 to being.

Code:
Code:
function SubtractPtTwo()
{
TestVarMe = TestVarMe - 0.2;
Debug.trace("TestVarMe " + TestVarMe + "\n")
}



Debug after a few run throughs:
TestVarMe 0.8
TestVarMe 0.6
TestVarMe 0.4
TestVarMe 0.2
TestVarMe 5.55112e-017
TestVarMe -0.2
TestVarMe -0.4
TestVarMe -0.6
TestVarMe -0.8
TestVarMe -1
TestVarMe -1.2
TestVarMe -1.4
TestVarMe -1.6
TestVarMe -1.8
TestVarMe -2
TestVarMe -2.2


If I change the subtraction to 0.25, it works, but 0.2 just throws up 5.55112e-017

Thanks, LMC

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Code: 5.55112e-017 instead of 0
PostPosted: June 21st, 2010, 11:50 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Quote:
throws up 5.55112e-017
That is probably just a ZERO with a very small amount of positive spin.

If you started with a value of 0.800, that should not happen. But if you've done some earlier calculations, it might be some residual small value.

_________________
_good things come to those who wait(0)_


For this message Lar_123 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Code: 5.55112e-017 instead of 0
PostPosted: June 21st, 2010, 2:15 pm 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
See attached sample, started from scratch, with no other code. Still the same out come.


You do not have the required permissions to view the files attached to this post.

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Code: 5.55112e-017 instead of 0
PostPosted: June 21st, 2010, 9:38 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Hi LMC,

Not uncommon when programming in Opusscript, C++ etc. Computers cannot store exact values of floating point numbers. Google "machine epsilon" to understand the issues involved, or check out the page below for a basic explanation:

http://www.akiti.ca/MachEps.html

Just apply a correction when the number approaches zero.
Change your script to::

function SubtractPtTwo()
{
TestVarMe = TestVarMe - SubtractVar;
if(Math.abs(TestVarMe)<0.000001)
{
TestVarMe=0;
}
Debug.trace("TestVarMe " + TestVarMe + "\n")
}

Paul


For this message Paul has been thanked by : lmc, mackavi


Last edited by Paul on June 22nd, 2010, 9:43 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Code: 5.55112e-017 instead of 0
PostPosted: June 22nd, 2010, 1:19 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Paul,

Quote:
if(Math.abs(TestVarMe)<0.000001)
(okay, this is more of a joke :roll: ) I am 'non-plussed'. :wink:

_________________
_good things come to those who wait(0)_


For this message Lar_123 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Code: 5.55112e-017 instead of 0
PostPosted: June 22nd, 2010, 9:32 am 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
Paul wrote:
Not uncommon when programming in Opusscript, C++ etc. Computers cannot store exact values of floating point numbers.


If anyone has Opus 6, can you try the same code to see if it works? I hope I don't have to change old publications to check for this.

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Code: 5.55112e-017 instead of 0
PostPosted: June 22nd, 2010, 9:49 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Happens in Opus 4,5,6 and 7.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


For this message mackavi has been thanked by : lmc


Top
 Profile Visit website  
 
 Post subject: Re: Code: 5.55112e-017 instead of 0
PostPosted: June 22nd, 2010, 11:19 am 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
mackavi wrote:
Happens in Opus 4,5,6 and 7.


That's good to know, so code will have the same outcome across the versions.

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 60 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
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group