[This message was posted by Dimitry  London of Morgan Stanley <[EMAIL 
PROTECTED]> to the "FAST Protocol" discussion forum at 
http://fixprotocol.org/discuss/46. You can reply to it on-line at 
http://fixprotocol.org/discuss/read/1555bebd - PLEASE DO NOT REPLY BY MAIL.]

Daniel, thanks very much, this approach looks very promising. I will run 
performance tests in the next few days.

Dimitry

> Dimity, There are two ways to look at this problem. If you know ahead of
> time that you are going to always use a fixed number of decimal
> precision (again, let's say your business rules require a precision of 4
> decimal points), and you have already either rounded your float to those
> 4 points of precision, or truncation is okay for your application, then
> the conversion is simple:
> 
> float x = 123.4500 int64_t mantissa = (int64_t)(x * 10000); int32_t
> exponent = 4;
> 
> 
> The more complicated case is when you are trying to generically convert
> a floating point number to a FAST scaled decimal with
> a.) not losing any precision, and
> b.) optimizing the exponent as to keep the mantissa as small as
>   possible.
> 
> For this, take a look at modf() in the standard C library. It breaks a
> float into the whole and fractional parts. You can then cast or convert
> the float whole and fractional parts to integers. Next, you would remove
> any unnecessary precision from the fractional integer by using a mod and
> divide by 10 while there are trailing zeros left.
> 
> Finally, to create the FAST scaled decimal mantissa, you must determine
> the FAST exponent by inspecting the size of the fractional integer, and
> then adjust the whole integer by that factor, and add back the
> fractional part.
> 
> I am working on C/C++ an example for you...
> 
> /Daniel


[You can unsubscribe from this discussion group by sending a message to 
mailto:[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Financial Information eXchange" group.
To post to this group, send email to FIX-Protocol@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/FIX-Protocol?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to