vpiotr / decimal_for_cpp

Decimal data type for C++
273 stars 68 forks source link

Added mantissa and exponent based constructor, get and set. #21

Closed samireu closed 8 years ago

samireu commented 8 years ago

There are some use cases that need conversion from and to a decimal mantissa and exponent format. Ex.: FAST/FIX protocol. I use it and think it would be nice to have this included.

vpiotr commented 8 years ago

Thanks for your interest, however I don't think it's a good idea to include that code. 1) "Mantissa / exponent" format is used rather for scientific values (not money or other financial values). 2) This code can be external (you can use set/getUnbiased, with-precision constructor, pack/unpack).

There are also some technical issues with this code which you could fix for your own fork: a) you are using constructor overload for int which is not safe at all, because int64 version already exists for different purpose. b) you are using int instead of int64 so overflow can arise c) you are not using included rounding policy

samireu commented 8 years ago

1) The FAST/FIX Protocol vastly used to stream market data on the exchanges has a decimal field to represent prices that use the "Mantissa/Exponent" format. 2) I'll do that then..

a) true, b) true, wouldn't happen on the range i'm working with, but should be changed. c) There's no rounding going on on this code.

Thank you for your feedback.

vpiotr commented 8 years ago

At the end I found some documentation about this FIX/FAST protocol, so your change is added with some minor changes. See "decimalWithExponent" for tests which show how to use it.

Thanks!