On 28/09/13 15:56, MrSmith wrote:
This code fails:
rational(0, 1) * rational(1, 1);
object.Error: Integer Divide by Zero
----------------
0x00408228 in int std.rational.gcf!(int, int).gcf(int, int) at
C:\rational\rational.d(878)
0x0040820A in int std.rational.gcf!(int, int).gcf(int, int) at
C:\rational\rational.d(870)
0x004082E7 in std.rational.Rational!(int).Rational
std.rational.Rational!(int).Rational.opOpAssign!("*",
std.rational.Rational!(int).Rational).opOpAssign(std.rational.Rational!(int).Rational)
at C:\rational\rational.d(235)
0x004087C3 in std.rational.Rational!(int).Rational
std.rational.Rational!(int).Rational.opBinary!("*",
std.rational.Rational!(int).Rational).opBinary(std.rational.Rational!(int).Rational)
at C:\rational\rational.d(218)
0x0040880C in _Dmain at C:\rational\test.d(8)
0x0040C7EC in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).void runMain()
0x0040C827 in extern (C) int rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).void runAll()
0x0040C425 in _d_run_main
0x0040A064 in main
0x769C33AA in BaseThreadInitThunk
0x77C19EF2 in RtlInitializeExceptionChain
0x77C19EC5 in RtlInitializeExceptionChain
----------------
It seems to me like gcf is not properly implemented. Also why its name is gcf
(greatest common factor) and not gcd (greatest common divisor)?
Good catch, thank you!
What compiler and options are you using to get that detailed error report? With
dmd -main -unittest -debug rational.d I get only: "Floating point exception
(core dumped)". (Albeit I'm on Linux not Windows, I guess that might make a
difference.)