Mercurial Hosting > luan
comparison core/src/luan/impl/ModExpr.java @ 446:bbad2d06f728
remove automatic conversion from string to number
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 04 May 2015 16:21:17 -0600 |
parents | 6e11eace1091 |
children | b48cfa14ba60 |
comparison
equal
deleted
inserted
replaced
445:cc7d246bda2a | 446:bbad2d06f728 |
---|---|
1 package luan.impl; | 1 package luan.impl; |
2 | 2 |
3 import luan.Luan; | |
4 import luan.LuanException; | 3 import luan.LuanException; |
5 import luan.LuanSource; | 4 import luan.LuanSource; |
6 | 5 |
7 | 6 |
8 final class ModExpr extends BinaryOpExpr { | 7 final class ModExpr extends BinaryOpExpr { |
12 } | 11 } |
13 | 12 |
14 @Override public Object eval(LuanStateImpl luan) throws LuanException { | 13 @Override public Object eval(LuanStateImpl luan) throws LuanException { |
15 Object o1 = op1.eval(luan); | 14 Object o1 = op1.eval(luan); |
16 Object o2 = op2.eval(luan); | 15 Object o2 = op2.eval(luan); |
17 Number n1 = Luan.toNumber(o1); | 16 if( o1 instanceof Number && o2 instanceof Number ) { |
18 Number n2 = Luan.toNumber(o2); | 17 double d1 = ((Number)o1).doubleValue(); |
19 if( n1 != null && n2 != null ) { | 18 double d2 = ((Number)o2).doubleValue(); |
20 double d1 = n1.doubleValue(); | |
21 double d2 = n2.doubleValue(); | |
22 return d1 - Math.floor(d1/d2)*d2; | 19 return d1 - Math.floor(d1/d2)*d2; |
23 } | 20 } |
24 return arithmetic(luan,"__mod",o1,o2); | 21 return arithmetic(luan,"__mod",o1,o2); |
25 } | 22 } |
26 } | 23 } |