Floating point numbers

There is a native integer type in MPS. Is there also a Double or a Float type? I couldn't find one.

Thanks in advance!

Regards
mschalk
2
5 comments
I guess you mean types for properties in language structure definition - yes, there are types derived from string and constraining the values by a regex:
  • _FPNumber_String for doubles
  • _FloatNumberValue for floats

Cheers,

Vaclav
2
Avatar
Permanently deleted user
Thanks for your reply Vaclav!
I added the jetbrains.mps.lang.structure + jetbrains.mps.baseLanguage to my own language.
However I can't define the mentioned Types from above for my property in structure definition.
0
It could be because your structure model misses a dependency on j.m.baselanguage.structure. You may try Control/Cmd + R and type _FPNumber_String - this could set the dependencies for you.

Vaclav
1
Avatar
Permanently deleted user
Thank you for your help, Vaclav!
Finally it's working!
0
Avatar
Permanently deleted user

This will actually provide you with a string representing a (floating point) number, which can then be parsed through Double.parseDouble and related functions.

Is it possible to add Java behavior to these constrained string representations, so that we can avoid the boilerplate Double.parseDouble (and e.g. provide a default null when a NumberFormatError is thrown)

0

Please sign in to leave a comment.