[xsd-users] comparison operation

Rizzuto, Raymond Raymond.Rizzuto at sig.com
Fri Aug 29 12:36:44 EDT 2008


This link works: http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf

-----Original Message-----
From: Rizzuto, Raymond
Sent: Friday, August 29, 2008 12:16 PM
To: 'Boris Kolpackov'; 'Rizzuto, Raymond'
Cc: 'xsd-users at codesynthesis.com'
Subject: RE: [xsd-users] comparison operation

Boris,

I can't access the first URL - I get an "Object not found!| Message when I try.  I believe that is the same link as from your 3.2.0 beta1 release posting, and I did look at that 2 days ago, so maybe it will be back later.

I'm hoping I can set the precision to 6 places so that timestamps will round trip at the microsecond range.

I'd be interested in reading the post about VC++ and round-trip for floats if you can find it.  I'm targeting Linux currently, but would like to understand the issue in case it can happen in other environments.

Ray


-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Thursday, August 28, 2008 4:20 PM
To: Rizzuto, Raymond
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] comparison operation

Hi Ray,

Rizzuto, Raymond <Raymond.Rizzuto at sig.com> writes:

> Is there a way to use the new 3.2.0 feature that address the precision
> of float/double to "fix" the representation issue?
>
> I.e. if my original double is rounded to XSD_CXX_TREE_DOUBLE_PRECISION
> places.  If I take the rounded value, serialize and deserialize it via
> my XSD-generated library, would the deserialized value be guaranteed to
> compare equal to the rounded version I serialized?

This is a tricky question. First, even if in your program the decimal
representation of a floating point number is rounded to some number of
digits, there is no guarantee that the actual binary representation
will contain the same number of digits. Here is an example (taken from
the paper mentioned below):

float f = 3.1459; // the actual value stored in f is 3.1459001

I believe the way to achieve what you want is to serialize all
potentially significant digits as explained in this paper:

http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf

You can achieve this in XSD 3.2.0 by defining the following macros
when compiling your program:

XSD_CXX_TREE_FLOAT_PRECISION_MAX
XSD_CXX_TREE_DOUBLE_PRECISION_MAX
XSD_CXX_TREE_DECIMAL_PRECISION_MAX

There is, however, another potential problem: it does not seem to
be guaranteed that the C++ runtime will always be able to preserve
all the digits when reading a floating point number serialized with
such a precision. I remember reading on some mailing list that the
VC++ runtime is unable to round-trip without loss in some cases (I
think it was one of the Boost mailing lists, if you would like, I
can try to find those posts).

One alternative would be to customize the float/double/decimal
types and implement their parsing/serialization using floating
point routines that are known to preserve all potentially
significant digits during serialization and parsing. One such
library seems to be netlib/fp though I haven't used it myself:

http://www.netlib.org/fp/index.html

The 'custom/double' example shows how to customize the double
XML Schema built-in type.

Boris



IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.




More information about the xsd-users mailing list