digitalmars.D.learn - Integer division by zero results in floating-point exception !?
- David Finlayson (17/17) Apr 01 2007 Why does the following code result in a floating-point exception?
- Jarrett Billingsley (4/20) Apr 01 2007 Maybe it depends on the system? On Windows I get the error "Integer Div...
- David Finlayson (8/12) Apr 01 2007 My system is:
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (2/5) Apr 02 2007 I cannot catch that exception either. Ubuntu 7.04, dmd 1.010.
- Johan Granberg (3/9) Apr 02 2007 It is probably not an D exception but a unix signal, if I remember corec...
- David Finlayson (2/4) Apr 02 2007 So, is this a bug or a feature? If it is normal, it seems like this unde...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (12/17) Apr 02 2007 The hardware exceptions are considered "part of" the D mechanisms too,
- Dan (3/3) Apr 03 2007 The x86 architecture will perform either a fault or a trap when the inst...
Why does the following code result in a floating-point exception? /** * PROGRAM: div0.d * * Test integer division by zero */ import std.stdio; void main(char[][] args) { int a = 2; int b = 0; writefln("a/b = ", a/b); } $ bud div0.d $ ./div0 Floating point exception (core dumped)
Apr 01 2007
"David Finlayson" <david.p.finlayson gmail.com> wrote in message news:euom4m$2lmg$1 digitalmars.com...Why does the following code result in a floating-point exception? /** * PROGRAM: div0.d * * Test integer division by zero */ import std.stdio; void main(char[][] args) { int a = 2; int b = 0; writefln("a/b = ", a/b); } $ bud div0.d $ ./div0 Floating point exception (core dumped)Maybe it depends on the system? On Windows I get the error "Integer Divide by Zero".
Apr 01 2007
Jarrett Billingsley Wrote:Maybe it depends on the system? On Windows I get the error "Integer Divide by Zero".My system is: Digital Mars D Compiler v1.009 running on (Ubuntu) If that combo is up-to-date, then I will try and report a bug. I think the program is dumping core and not emitting a proper exception anyway. David
Apr 01 2007
David Finlayson wrote:If that combo is up-to-date, then I will try and report a bug. I think the program is dumping core and not emitting a proper exception anyway.I cannot catch that exception either. Ubuntu 7.04, dmd 1.010.
Apr 02 2007
Jari-Matti Mäkelä wrote:David Finlayson wrote:It is probably not an D exception but a unix signal, if I remember corectlly unix gives a process the floating point exception signal on divide by 0.If that combo is up-to-date, then I will try and report a bug. I think the program is dumping core and not emitting a proper exception anyway.I cannot catch that exception either. Ubuntu 7.04, dmd 1.010.
Apr 02 2007
Johan Granberg Wrote:It is probably not an D exception but a unix signal, if I remember corectlly unix gives a process the floating point exception signal on divide by 0.So, is this a bug or a feature? If it is normal, it seems like this undermines the exception mechanism built into the language.
Apr 02 2007
David Finlayson wrote:The hardware exceptions are considered "part of" the D mechanisms too, for instance dereferencing a null pointer will give you a similar error. BTW; If I run your program (with the debugger) on Mac OS X, I get: Program received signal EXC_ARITHMETIC, Arithmetic exception. 0x00002e21 in D main (args={length = 1, ptr = 0x300550}) at div0.d:13 13 writefln("a/b = ", a/b); Interestingly, this only happens on X86. The PPC happily outputs: a/b = 0 So I guess it is ultimately up to how the architecture handles it... But for the Intel architecture you probably want to check for it ? --andersIt is probably not an D exception but a unix signal, if I remember corectlly unix gives a process the floating point exception signal on divide by 0.So, is this a bug or a feature? If it is normal, it seems like this undermines the exception mechanism built into the language.
Apr 02 2007
The x86 architecture will perform either a fault or a trap when the instruction DIV or MOD is used, and the second operand is a 0. A fault or a trap, is when it ceases execution and instead executes: function* IDT[0x??], which is the divide by zero handler for the system. Each operating system has to write their own handler, and it's often just a "throw an error to the command line, durr". Faults stop before the instruction, Traps stop after, or the other way around. Can't remember.
Apr 03 2007