[xsd-users] Re: Parsing float value

Boris Kolpackov boris at codesynthesis.com
Wed Feb 19 09:09:25 EST 2020


HUY Seav-Er - partenaire <seav-er-externe.huy at edf.fr> writes:

> In my XSD file, I defined a value with xs:float and the parsing of XML
> file is done with cxx-tree.
> 
> For example, in my XML, the value is 1.49451193e-06, I get with 16
> digits printing, 1.49451193465211e-06. To do the same exercise, I
> change in the XSD file the type to xs:double and the output is as
> it is in the XML. Moreover, when I cast this output to float, I
> get the same result 1.49451193465211e-06 as xs:float defintion.
> 
> My question is whether the parsing is always done with double
> precision and convert to float in case of xs:flot in XSD definition.

Parsing is done as float/double respectively. You can see the code
in libxsd/xsd/cxx/tree/parsing/{float,double}.hxx. As you are
probably aware, floating-point numbers do not represent all possible
values and the exact set of values depends on the representation
(float, double, etc). So I think what happens in your case is the
value in question is exactly representable as double but not as
float.

Also see the serialization side, which is another messy story with
some macros that may help you get what you want. See the code in
libxsd/xsd/cxx/tree/serialization/{float,double}.hxx.



More information about the xsd-users mailing list