mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
parent
2873a17c55
commit
b2ea083eeb
@ -4001,12 +4001,22 @@ eval6 (
|
||||
* When either side is a float the result is a float.
|
||||
*/
|
||||
if (use_float) {
|
||||
if (op == '*')
|
||||
if (op == '*') {
|
||||
f1 = f1 * f2;
|
||||
else if (op == '/') {
|
||||
/* We rely on the floating point library to handle divide
|
||||
* by zero to result in "inf" and not a crash. */
|
||||
f1 = f2 != 0 ? f1 / f2 : INFINITY;
|
||||
} else if (op == '/') {
|
||||
// Division by zero triggers error from AddressSanitizer
|
||||
f1 = (f2 == 0
|
||||
? (
|
||||
#ifdef NAN
|
||||
f1 == 0
|
||||
? NAN
|
||||
:
|
||||
#endif
|
||||
(f1 > 0
|
||||
? INFINITY
|
||||
: -INFINITY)
|
||||
)
|
||||
: f1 / f2);
|
||||
} else {
|
||||
EMSG(_("E804: Cannot use '%' with Float"));
|
||||
return FAIL;
|
||||
|
28
test/functional/eval/operators_spec.lua
Normal file
28
test/functional/eval/operators_spec.lua
Normal file
@ -0,0 +1,28 @@
|
||||
local helpers = require('test.functional.helpers')
|
||||
local eq = helpers.eq
|
||||
local eval = helpers.eval
|
||||
local clear = helpers.clear
|
||||
|
||||
describe('Division operator', function()
|
||||
before_each(clear)
|
||||
|
||||
it('returns infinity on {positive}/0.0', function()
|
||||
eq('str2float(\'inf\')', eval('string(1.0/0.0)'))
|
||||
eq('str2float(\'inf\')', eval('string(1.0e-100/0.0)'))
|
||||
eq('str2float(\'inf\')', eval('string(1.0e+100/0.0)'))
|
||||
eq('str2float(\'inf\')', eval('string((1.0/0.0)/0.0)'))
|
||||
end)
|
||||
|
||||
it('returns -infinity on {negative}/0.0', function()
|
||||
eq('-str2float(\'inf\')', eval('string((-1.0)/0.0)'))
|
||||
eq('-str2float(\'inf\')', eval('string((-1.0e-100)/0.0)'))
|
||||
eq('-str2float(\'inf\')', eval('string((-1.0e+100)/0.0)'))
|
||||
eq('-str2float(\'inf\')', eval('string((-1.0/0.0)/0.0)'))
|
||||
end)
|
||||
|
||||
it('returns NaN on 0.0/0.0', function()
|
||||
eq('str2float(\'nan\')', eval('string(0.0/0.0)'))
|
||||
eq('str2float(\'nan\')', eval('string(-(0.0/0.0))'))
|
||||
eq('str2float(\'nan\')', eval('string((-0.0)/0.0)'))
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue
Block a user