RatNum value = ((Number)IokeObject.data(on)).value;
if(value instanceof IntFraction) {
IntNum num = value.numerator();
IntNum den = value.denominator();
BigDecimal nums = new BigSquareRoot().get(num.asBigDecimal());
BigDecimal dens = new BigSquareRoot().get(den.asBigDecimal());
try {
num = IntNum.valueOf(nums.toBigIntegerExact().toString());
den = IntNum.valueOf(dens.toBigIntegerExact().toString());
return context.runtime.newNumber(new IntFraction(num, den));
} catch(ArithmeticException e) {
// Ignore and fall through
}
}
if(RatNum.compare(value, IntNum.zero()) < 1) {
final IokeObject condition = IokeObject.as(IokeObject.getCellChain(context.runtime.condition,
message,
context,
"Error",
"Arithmetic"), context).mimic(message, context);
condition.setCell("message", message);
condition.setCell("context", context);
condition.setCell("receiver", on);
context.runtime.errorCondition(condition);
}
return context.runtime.newDecimal(new BigSquareRoot().get(value.asBigDecimal()));
}
}));
number.registerMethod(runtime.newNativeMethod("returns true if the left hand side number is equal to the right hand side number.", new TypeCheckingNativeMethod("==") {
private final TypeCheckingArgumentsDefinition ARGUMENTS = TypeCheckingArgumentsDefinition