Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Inaccurate results in operations on Real types
Inaccurate results in operations on Real types [message #674632] Fri, 27 May 2011 16:00 Go to next message
Mehrdad Saadatmand is currently offline Mehrdad SaadatmandFriend
Messages: 6
Registered: March 2011
Junior Member
Hi,

In a QVT transformation, I have a variable which gets its value as:
xxx..oclAsType(Real);

My problem is that when I do calculations on such variables I get inaccurate results. For example I have 1.0 and 0.8 and when I subtract, I get 0.199999999996 instead of 0.2 !

How is it possible to fix this problem?

thanks,
Mehrdad
Re: Inaccurate results in operations on Real types [message #674654 is a reply to message #674632] Fri, 27 May 2011 17:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Mehrdad

The mature implementation of OCL that QVTo extends uses Java's Double,
so you get the same result as you would for 1.0 - 0.8 in Java.

At some level this is a problem in any language; you need to ignore
differences that lie within epsilon, the difference between adjacent values.

The new implementation of OCL uses Java's BigDecimal so you will get
much much greater precision, but still not perfect since 0.8 has a 1/5
factor that has no exact binary representation. This new version of OCL
certainly won't be in QVTo for Indigo and it's doubtful that it will be
in for Juno. I would expect that it will be Juno+1.

Regards

Ed Willink


On 27/05/2011 17:00, Mehrdad Saadatmand wrote:
> Hi,
>
> In a QVT transformation, I have a variable which gets its value as:
> xxx..oclAsType(Real);
>
> My problem is that when I do calculations on such variables I get
> inaccurate results. For example I have 1.0 and 0.8 and when I
> subtract, I get 0.199999999996 instead of 0.2 !
>
> How is it possible to fix this problem?
>
> thanks,
> Mehrdad
Re: Inaccurate results in operations on Real types [message #674955 is a reply to message #674654] Sun, 29 May 2011 18:16 Go to previous message
Mehrdad Saadatmand is currently offline Mehrdad SaadatmandFriend
Messages: 6
Registered: March 2011
Junior Member
Thanks Edward for the explanation.
Previous Topic:Eclipse OCL and UML State Machines
Next Topic:[Announce] Eclipse OCL 3.1.0 RC3 is now available
Goto Forum:
  


Current Time: Tue Mar 19 09:19:31 GMT 2024

Powered by FUDForum. Page generated in 0.01652 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top