mruby/mruby — pull request #492 by tsahara-iij (2012-10-16 09:19:38+00:00)
Title: raise ZeroDivisionError instead of crashing.

a) On OpenBSD/amd64, mruby dumps core when we call Integer#divmod with 0:

```
% bin/mruby -e 'p 1.divmod(0)'
zsh: floating point exception (core dumped) bin/mruby -e 'p 1.divmod(0)'
```

In contrast, CRuby raises an exception:

```
% ruby -e 'p 1.divmod(0)'
-e:1:in `divmod': divided by 0 (ZeroDivisionError)
from -e:1:in `

'
%
```

Integer#divmod is not defined in ISO Ruby but CRuby's behavior looks reasonable.

b) Integer#% and Float#% may return NaN:

```
% bin/mruby -e 'p 1 % 0'
NaN
% bin/mruby -e 'p 1.0 % 0.0'
NaN
```

But ISO Ruby says that "i % 0" should raise a ZeroDivisionError exception. CRuby implements that.

This pull-request makes Fixnum#%, Float#% and Fixnum#divmod compatible with CRuby.

- 1.1 % 0.0 = NaN
- 1 % 0.0 => ZeroDivisionError
- 1 % 0 => ZeroDivisionError
- 0 % 0 => ZeroDivisionError
- 0.0 % 0 => ZeroDivisionError
- 0 % 0.0 => ZeroDivisionError
- 1.divmod(0) => ZeroDivisionError
- 0.divmod(0) => ZeroDivisionError