Package gnu.math

Examples of gnu.math.RatNum


        rational.registerMethod(runtime.newNativeMethod("returns the square root of the receiver. this should return the same result as calling ** with 0.5", new NativeMethod.WithNoArguments("sqrt") {
                @Override
                public Object activate(IokeObject method, IokeObject context, IokeObject message, Object on) throws ControlFlow {
                    getArguments().getEvaluatedArguments(context, message, on, new ArrayList<Object>(), new HashMap<String, Object>());

                    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
View Full Code Here

TOP

Related Classes of gnu.math.RatNum

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.