[xsd-users] comparison operation
Raymond.Rizzuto at sig.com
Fri Aug 29 12:16:29 EDT 2008
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.
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
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:
You can achieve this in XSD 3.2.0 by defining the following macros
when compiling your program:
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:
The 'custom/double' example shows how to customize the double
XML Schema built-in type.
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