Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serialization of EFloat(seems to fail for small float values)
Serialization of EFloat [message #652920] Mon, 07 February 2011 15:35 Go to next message
Martin Jung is currently offline Martin JungFriend
Messages: 4
Registered: July 2009
Junior Member
Hi!

I was playing around with xtext reading files, transforming the Object trees values and serializing the modified tree when I stumbled over a XtextSerializationException.

I boiled it down to this:

I am using a Terminal rule for representing Floating point numbers like this (being lazy, i copied it somwhere):
terminal REALTYPE returns ecore::EFloat : (('-'|'+')? ( INT '.' INT | '.' INT | INT '.') ('e' ('-'|'+') INT)?) | ('-' INT);


It turns out that Serialization fails when small values of floats are used. Turned out further that exactly when float values "serialized" by standard java float->String conversion (as in System.err.println) switch over to scientific notation (which at my installation is at 0.00042f or 4.2E-4). As long as standard java does not switch the values rendering to scientific notation I do not get the XtextSerializationException.

The Question now is twofold: Is this behavior known or am I doing something wrong?
If I do nothing wrong, how do I get rid of the XtextSerializationException?

Any Help appreciated!
Re: Serialization of EFloat [message #652922 is a reply to message #652920] Mon, 07 February 2011 15:58 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what about writing a ValueConverter as docs say.

~ Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serialization of EFloat [message #652929 is a reply to message #652920] Mon, 07 February 2011 15:53 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Martin,

you'll have to define your own value converter that creates a string
which matches your terminal rule. Please refer to the docs for details.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 07.02.11 16:35, schrieb Martin Jung:
> Hi!
>
> I was playing around with xtext reading files, transforming the Object
> trees values and serializing the modified tree when I stumbled over a
> XtextSerializationException.
>
> I boiled it down to this:
>
> I am using a Terminal rule for representing Floating point numbers like
> this (being lazy, i copied it somwhere):
> terminal REALTYPE returns ecore::EFloat : (('-'|'+')? ( INT '.' INT |
> '.' INT | INT '.') ('e' ('-'|'+') INT)?) | ('-' INT);
>
> It turns out that Serialization fails when small values of floats are
> used. Turned out further that exactly when float values "serialized" by
> standard java float->String conversion (as in System.err.println) switch
> over to scientific notation (which at my installation is at 0.00042f or
> 4.2E-4). As long as standard java does not switch the values rendering
> to scientific notation I do not get the XtextSerializationException.
>
> The Question now is twofold: Is this behavior known or am I doing
> something wrong?
> If I do nothing wrong, how do I get rid of the XtextSerializationException?
>
> Any Help appreciated!
Re: Serialization of EFloat [message #653041 is a reply to message #652929] Tue, 08 February 2011 08:41 Go to previous message
Martin Jung is currently offline Martin JungFriend
Messages: 4
Registered: July 2009
Junior Member
Hi Christian & Sebastian.

Thanks for the fast RTFM, I deserved that (thats what you get from decaf).

As expected, the ValueConverter does exactly what I was trying to do.

Cheers,
Martin
Previous Topic:Resolving references time
Next Topic:Inferred superclasses
Goto Forum:
  


Current Time: Fri Apr 26 09:15:03 GMT 2024

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

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

Back to the top