mastercoin-MSC / mastercore

mastercore info
mastercoin.org
MIT License
24 stars 11 forks source link

Initial commit of removal of double #186

Closed ghost closed 9 years ago

ghost commented 9 years ago

I'm starting this PR to stimulate discussion of the removal of the use of 'double' in the metadex, to that end i've done three things:

1) changed the types of 'double' in mastercore_dex.cpp to 'cpp_dec_float_50' 2) changed the printf's to display a formatted string from the new type 3) added some casts for calculations that were implicitly casting to an integer

looking forward to the discussion!

dexX7 commented 9 years ago

cpp_dec_float_50 sounds pretty exotic, but a project wide precision which is not bound to architecture is probably indeed the way to go, but just in case: there is also long double.

What I suggest: create a header with:

#ifndef MASTERCORE_AMOUNT_H
#define MASTERCORE_AMOUNT_H

#include <boost/multiprecision/cpp_dec_float.hpp>

typedef boost::multiprecision::cpp_dec_float_50 MAmount;

#endif // MASTERCORE_AMOUNT_H

... and use it like this:

MAmount price;

When there is another change to a different format, say for example a switch to.. cpp_dec_float_100 or so, all you'd need to do is change a single line.

m21 commented 9 years ago

A typedef is great for sure. But I don't wanna be creating too many dozen line files. :) I don't expect us to be changing 50 digits to 100; really hoping not. If we gotta - let's do it now. long double is only 128 precision and is not portable, can't use it.

dexX7 commented 9 years ago

I don't wanna be creating too many dozen line files.

Hehe, I guess that's where I have a very different opinion. :p

FWIW: cpp_dec_float_50 is also just typedef number<cpp_dec_float<50> > cpp_dec_float_50; and it looks like you can use any number of digits, so intermediate values such as 75 are possible, too - if required.

ghost commented 9 years ago

Good item to note Dexx

we're beginning testing of phase 1 metadex very very soon, so i think this is on a higher priority than when i originally submitted it

typedefs todo? trying to keep things in sync with changes for the moment.