Opened 4 years ago

Closed 4 years ago

#10082 closed Bugs (fixed)

implicit cpp_rational(double)

Reported by: marc.glisse@… Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:



while trying to plug cpp_rational in our software, I noticed that the conversion from double is explicit, which complicates things quite a bit for me. I can't think of a reason why it needs to be explicit. The documentation seems to say that non-lossy conversions from builtin types are implicit, and converting from double to cpp_rational should be exact.

Attachments (0)

Change History (3)

comment:1 Changed 4 years ago by John Maddock

Ugh, I'm a bit conflicted by this: you're quite right that the double value is converted exactly, however making this implicit does allow you to shoot yourself in the foot, for example:

cpp_rational r(0.1);

Assigns the value 3602879701896397/36028797018963968 to r, which is probably not what was intended! Of course a naive user may just add the necessary cast and shoot themselves anyway, but on balance I think I'm marginally against making the conversion implicit.

comment:2 Changed 4 years ago by marc.glisse@…

Argh, please don't base your design on dumb users. Using expression templates in the first place will cause problems for dumb users (and even not so dumb ones). And the 0.1 issue is in my opinion orthogonal to implicit/explicit. The example as you wrote it already compiles (it uses the explicit constructor), you want to write it:

cpp_rational r = 0.1;

if it is supposed to be an argument against making it implicit. But the "problem" won't really become worse by making the constructor implicit.

comment:3 Changed 4 years ago by John Maddock

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain John Maddock.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.