gecko-dev/js/js2/java/JSDouble.java

111 lines
2.7 KiB
Java
Raw Normal View History

1999-05-20 00:14:26 +00:00
class JSDouble extends JSNumber {
JSDouble(double p)
{
d = p;
}
1999-05-20 00:14:26 +00:00
JSDouble(String s)
{
d = new Double(s).doubleValue();
}
String print(String indent)
{
return indent + "JSDouble " + d + "\n";
}
1999-05-26 01:01:07 +00:00
public String toString()
{
return Double.toString(d);
}
1999-05-28 19:00:48 +00:00
JSValue eval(Environment theEnv)
1999-05-20 00:14:26 +00:00
{
1999-05-28 19:00:48 +00:00
return this;
}
1999-05-28 19:00:48 +00:00
JSValue plus(Environment theEnv) {
return this;
}
1999-05-28 19:00:48 +00:00
JSValue minus(Environment theEnv) {
return new JSDouble(-d);
}
1999-05-28 19:00:48 +00:00
JSValue add(Environment theEnv, JSValue rV) {
if (rV instanceof JSString)
return toJSString(theEnv).add(theEnv, rV);
else
return new JSDouble(d + rV.toJSDouble(theEnv).d);
}
1999-05-28 19:00:48 +00:00
JSValue subtract(Environment theEnv, JSValue rV) {
return new JSDouble(d - rV.toJSDouble(theEnv).d);
}
1999-05-28 19:00:48 +00:00
JSValue multiply(Environment theEnv, JSValue rV) {
return new JSDouble(d * rV.toJSDouble(theEnv).d);
}
1999-05-28 19:00:48 +00:00
JSValue divide(Environment theEnv, JSValue rV) {
return new JSDouble(d / rV.toJSDouble(theEnv).d);
}
1999-05-28 19:00:48 +00:00
JSValue remainder(Environment theEnv, JSValue rV) {
return new JSDouble(d % rV.toJSDouble(theEnv).d);
}
1999-05-28 19:00:48 +00:00
JSValue gt(Environment theEnv, JSValue rV) {
return (d > rV.toJSDouble(theEnv).d) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
1999-05-28 19:00:48 +00:00
JSValue ge(Environment theEnv, JSValue rV) {
return (d >= rV.toJSDouble(theEnv).d) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
1999-05-28 19:00:48 +00:00
JSValue lt(Environment theEnv, JSValue rV) {
return (d < rV.toJSDouble(theEnv).d) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
1999-05-28 19:00:48 +00:00
JSValue le(Environment theEnv, JSValue rV) {
return (d <= rV.toJSDouble(theEnv).d) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
1999-05-28 19:00:48 +00:00
JSValue eq(Environment theEnv, JSValue rV) {
return (d == rV.toJSDouble(theEnv).d) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
1999-05-28 19:00:48 +00:00
JSValue ne(Environment theEnv, JSValue rV) {
return (d != rV.toJSDouble(theEnv).d) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
1999-05-26 01:01:07 +00:00
JSDouble toJSDouble(Environment theEnv) {
return this;
}
1999-05-26 01:01:07 +00:00
JSValue toPrimitive(Environment theEnv, String hint) {
1999-05-21 00:54:26 +00:00
return this;
}
1999-05-26 01:01:07 +00:00
JSInteger toJSInteger(Environment theEnv) {
return new JSInteger((int)d);
}
1999-05-26 01:01:07 +00:00
JSBoolean toJSBoolean(Environment theEnv) {
1999-05-21 00:54:26 +00:00
return ((d == d) && (d != 0.0)) ? JSBoolean.JSTrue : JSBoolean.JSFalse;
}
1999-05-26 01:01:07 +00:00
JSString toJSString(Environment theEnv) {
return new JSString(Double.toString(d));
}
1999-05-26 01:01:07 +00:00
JSObject toJSObject(Environment theEnv) {
return new NativeNumber(d);
1999-05-20 00:14:26 +00:00
}
1999-05-26 01:01:07 +00:00
1999-05-20 00:14:26 +00:00
double d;
}