Skip to main content



      Home
Home » Modeling » OCL » Inaccurate results in operations on Real types
Inaccurate results in operations on Real types [message #674632] Fri, 27 May 2011 12:00 Go to next message
Eclipse UserFriend
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 13:47 Go to previous messageGo to next message
Eclipse UserFriend
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 14:16 Go to previous message
Eclipse UserFriend
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: Fri May 16 18:07:58 EDT 2025

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

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

Back to the top