d-money ctor(string) has bug, be careful! EUR("1.23456") ==> ctor ==> 3.3456EUR
mw
mingwu at gmail.com
Fri May 22 05:26:45 UTC 2020
Hi,
(if you are not a user of this package:
https://code.dlang.org/packages/money
you can stop reading now.
I'm a D newbie, not sure if this the best place to send this
alert, but this library package is about money and has a relative
large user base:
Download Stats:
6 downloads today
122 downloads this week
966 downloads this month
9300 downloads total
I think it worth attention from a big audience group).
The issue found is here:
https://github.com/qznc/d-money/issues/11
----------------------------------------------------------------------------------------
$ cat m.d
/+dub.sdl:
dependency "money" version="~>2.3.1"
+/
import std.stdio;
import money;
alias EUR = currency!("EUR");
void main() {
EUR x = EUR( 1.23456 );
EUR y = EUR("1.23456");
writeln(x);
writeln(y);
assert(x == y);
}
$ dub m.d
1.2346EUR
3.3456EUR
core.exception.AssertError at m.d(15): Assertion failure
----------------
??:? _d_assertp [0x52b005]
m.d:15 _Dmain [0x4dec36]
Program exited with code 1
The reason is pow10(x) doesn't handle negative x at all.
https://github.com/qznc/d-money/blob/master/source/money.d#L64
when called from
https://github.com/qznc/d-money/blob/master/source/money.d#L107
with x = -1
BTW, why use a recursive function instead of a simple loop to
calc pow10?
More information about the Digitalmars-d
mailing list