Boost logo

Boost :

Subject: Re: [boost] [decimal] Proposed portable implementation ofstd::decimal
From: Josh Quigley (0zeroth_at_[hidden])
Date: 2012-05-21 20:32:57


Hi Chris,

> > A first draft of this library is available at
> > https://sourceforge.net/projects/stddecimal/
> > Runs on MSVC10 and gcc 4.6.3.

> > Wraps the Intel implementation only,
> In my opinion, this is a good start. But to really improve the
> portability and usefulness of your proposal, you might want
> to consider writing your own portable decimal back end.

As tempting as this sounds, I don't have the skill, and certainly don't have the
time. If anyone finds this idea appealing, I'm more than happy to help out with
testing.

> As far as I know, you simply won't get the third party code into boost.
> Perhaps I'm wrong here. But the best you can do is create a front
> end C++ implementation in as portable a way as possible and
> provide a mechanism for linking with prebuilt versions of the
> 3rd-party library. This is, for example, what we have done with
> GNU GMP, MPFR and MPIR in association with the proposed
> Boost.Multiprecision library.

Sounds reasonable. Is the GPL license compatible with the boost license? The
decNumber is available under GPL. We should also contact the library authors and
see if they will grant permission to include the libraries under terms amenable
to the boost license - both libraries were made available for gcc but I'm not
sure if both are under the GPL. How would 'boost' go about this - I could
contact the authors but I wouldn't like to pose as a boost representative
without some sort of permission!

> But we would need to figure out how this would best fit into
> the existing (and potentially future) numerical context of boost.
> [SNIP] here's what I would suggest:
>
> 1) Consider writing your own fully portable, boost-owned decimal.
> Provide the Intel compatibility as an optimized back-end for
> selected architecture. You would need a bit more software
> architecture to support multiple back ends.

As above regarding writing own backend. Regarding software architecture, the
rudiments are in place (a half-implementation using decNumber is done but not
committed).

> 2) I'm probably jumping the gun here, but you may want to take a look
> at the back-end requirements for a number type in the proposed
> Boost.Multiprecision. You might eventually want to target compatibility
> with this potential boost library.

I'll take a look, but the goal as I see it is complying with the std::decimal
proposal - that is, to fill the gap until it becomes standard and all compilers
support it. This doesn't preclude extended functionality being bolted on.

> 3) You have some amounts of code in cpp source files. In my
> opinion, a decimal implementation should be header-only.
> The one exception is the use of library code mentioned earlier.
> One of the powers of boost is its portability. And this is strongly
> facilitated with its emphasis on header-only libraries.

I'd have though the implementation of the actual numerics is complex enough to
benefit from being compiled into a library - but I have little insight into the
pros and cons of the two approaches.

As an alternative, would making the back-end C compliant (or C-with-pass-by-
reference) be enough to facilitate portability? Both 3rd party backends are C,
and I see no reason for a boost owned version to be much different.

The wrappers I've provided thus far could certainly be header only, but I'm
working on the assumption that's pointless if you are insisting on a compiled
back-end.

> 4) Is there any connection between decimal and fixed-point?
> If so, do you want to contact Vicente Escriba who is concerned
> with fixed-point?

I don't think there is a connection apart from optionally providing direct
conversion between the two, however I'll take a closer look at the fixed point
library.

> 5) Do you need any elementary transcendental functions
> such as sin, cos, tan, exp, log, etc. Do you want to support
> any of these? Do your potential users need them? If so,
> I could potentially point you in the right direction for getting
> started on some potentially sensible algorithms in the digit
> ranges you are targeting.

Yes, I was planning on using the versions of these functions supplied by the 3rd
party code. Also, the standard doesn't specify the accuracy of most of these
functions, so conversion to and from floating point is an option in the early
stages.

> Again, to iterate lika a broken record...
>
> Why don't you make a first attempt at writing the code
> for the *guts* of the decimal types. I would be in a position
> to assist you with this, if you would like. However, I will be
> available at the earliest in fall for any significant contribution
> on a project with this level of complexity.

It'd be a great project, but I don't have the time. My primary goal is to
implement this for my own purposes - given C libraries and a blueprint of the
C++ interface a freely available this is a fairly trivial task.

Even if this library doesn't make it into boost proper, I think it will still be
valuable to have a proven wrapper + 3rd party combo that developers can use with
some confidence as to it's reliability - even if they have to grab both parts
separately. Since it's following a proposed standard, users can expect
continuing support - at the very least that something similar will eventually be
provided by compilers.

At any rate, having the wrapper with support for multiple back-ends and all the
tests in place will be a good starting point for anyone who should wish to
implement their own version of a floating point decimal!

Thanks again for such detailed feedback!
Regards,

Josh.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk