-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
boost::mp::number with cpp_dec_float backend and some strange initialization moments and a few strange implementation decisions #594
Comments
Thanks for a good post, @niXman. It is good to read your queries.
To be very terse (and I've never addressed John about this), I think long-term migration to a
... is absolutely, definitely, inefficient legacy code. This code is based on work from last century and is in dire need of refactoring. Personally, I wouldn't mess around with About the top-level conversion rules WRT docs, I'll punt to John... Cc: @jzmaddock and @mborland |
|
+1 on supporting string views. I wonder if we can conceptualize what makes a string-view type class and just provide a template constructor with no actual dependency? With regard to construction from string: the class is explicitly constructible from string types (ie the constructor is there, but marked as
Is just fine. |
I'm confused why actually deal with |
It's pointer to first and size. It's generally equivalent to calling func(str.data(), str.data() + str.size()). It should be an easy concept since it only needs those two members. |
Which boils down to first and last. Yes. I am aware. This is exactly why I'm pressing on with a We already know if the underlying type is integral/floating-point (from the backend traits) and if any default radices are needed, we have these from So clients could create a multiprecision number |
A second (simple) option which I've used in other projects, retains the This type of mash-up would be simple to harmonize with the existing code of today. Furthermore, it would allow clients to use Independently of this, the inefficiency of |
got it, thanks!
oh, great!
oh, you are right!
OK, I will refactor this way. |
I've heard a few opinions over the years. Often times there is something like this, meaning it gets done. Other developers, however, warn that "your big-number class isn't a string, don't make it behave as one". They say keep such options as explicit as possible. I kind of agree with the second. |
hello, @ckormanyos, @mborland I think this is my first time I want to make changes to boost, so I have a few questions. I found this description of the process: https://github.com/boostorg/wiki/wiki/Getting-Started%3A-Overview but it looks to me like there are some steps missing.
or, can anyone just provide me the correct doc for dev process, please? best! |
It's a lot easier than you might think. Just about the simplest way for Multiprecision can be done more straightforwardly than described in the process for the entire monolithic Boost. We have standalone, so it's super simple to work with either Math or Multiprecision.
So for your include paths, just put in first the path to the "include" directory of the Multiprecision submodule, then as a second include path, the path to the normal Boost 1.84. You put the include of the submodule first since that will then get picked up by your compiler before picking up the 1.84 path. Do your coding that way, push to your branch. You might need to make some new tests. if so, we can cross this bridge when we get to it. |
got it, thanks! |
If you encounter difficulties with the setup, just query. It is quite simple so if there are problems, we can work them out. |
guys, I have a question. please look at this ctor: https://github.com/niXman/multiprecision/blob/develop/include/boost/multiprecision/number.hpp#L119 the question is, since the first one is a constructor - is there any reason to use the ie for noexcept spec: thanks! |
Yes: If you look at what the constructors actually do, the second passes the argument to the backend's constructor, while the first default constructs the backend and then assigns to it. Explanation: it's not a conceptual requirement that the backend is constructable from everything that class Hope that somewhat makes sense! BTW if this is to add support for string_views, I think it's probably a mistake to force backends to natively support them - many backends rely on external C libraries which can handle a So I guess a gold plated solution might be provide 3 constructors:
I would guess case 3 would need to be enable_if'ed on:
Such a constructor will not be noexcept in any circumstances, because it will presumably need to copy the character range to a new buffer (or a std::string)? |
oh, indeed, it is an incredibly suboptimal but yes, eventually we will still have to copy the range of characters into a temporary buffer before calling C backend... thank you @jzmaddock ! |
I suspect that allocating a temporary string is a trivial cost compared to the work that goes into parsing a multiprecision string. But of course the bitcoin designers probably said much the same thing :-/ |
Maybe some ideas could be found if you look into the new Boost.Charconv. I think the author was concerned with avoiding extraneous allocation. |
hello guys! some information. in order to get rid of all these MPFR/MPFI/MPC - depend on GMP, therefore I need to start with this library and its API. but, for some reason, no one wants to communicate with me, they are probably afraid to expand the API =) guys, maybe some of you have access to people working with GMP, could you please ping them to advance this issue? best! |
I think you have basically zero chance of getting all those disparate libraries to change their API's - remember they're C libraries, have ultra stable ABI's and basically could care less about C++ anyway :( |
although I'm not suggesting they change the API, but I'm suggesting they expand it with a new group of functions, I admit that they may simply not be interested in this... :( tomorrow I will work on the implementation of functionality similar to |
Word. Hi @niXman we do not have a direct line to the authors of these fine low-level backends either. We have done our best possible effort to wrap them based on our empirical observations of how they work. And they are well-specified, but we don't meddle with them, and don't aspire to do so. But at the end of the day, we wrap what we find. |
hello guys,
firstly: construction/assignments
let me refer to the documentation for
boost::mp::number
class:now please look at the code:
as far as you can see the only way to initialize the
number
class is to use thenumber::assign()
MF.so my first question is: why? is this a documentation mismatch? or is this a consequence of something being broken?
further about some controversial decisions in terms of optimization.
imagine we end up having to use
number::assign(std::string)
.in this case we will follow the path: number::assign(const std::string &) -> number::canonical_value(const std::string &) -> cpp_dec_float::operator=(const char* v) -> cpp_dec_float::rd_string(const char* s).
so, the
cpp_dec_float::rd_string(const char* s)
function is exactly the function that converts a string to thenumber
.OK, the function takes
const char *
as its argument.BUT, it creates a
std::string
object which is initialized with the value of the argument!that is, we had a
std::string
from which we receivedconst char *
just to create thestd::string
again!(in cases where the source string is longer than the SSO buffer - we will also perform additional allocation and deallocation! I'm not even talking about six calls to
std::string::substr()
)I briefly looked at the implementation of this function it seems to me that it is quite possible to change the implementation to use
boost::string_view
instead ofstd::string
.but there is another problem with this: based on this line - this library is meant to be used as the standalone library, and I don't know if
boost::string_view
is included in the package of the standalone library... (ideas?)I think if I can change the implementation of that function to use
boost::string_view
instead ofstd::string
, then it would make sense to change the signature of that function so it acceptsboost::string_view
instead ofconst char *
along with the necessary changes regarding the call that function.ideas?
best!
The text was updated successfully, but these errors were encountered: