All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jscl.math.function.Inverse Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show newest version
package jscl.math.function;

import jscl.math.Generic;
import jscl.math.JsclInteger;
import jscl.math.NotDivisibleException;
import jscl.math.Variable;

import javax.annotation.Nonnull;

public class Inverse extends Fraction {

	// inverse function: 1/g
	public Inverse(Generic generic) {
		super(JsclInteger.valueOf(1), generic);
	}

	public Generic selfExpand() {
		try {
			Generic parameter = parameter();
			/*try {
                   if (JsclInteger.ZERO.equals(parameter.integerValue())) {
                       throw new ArithmeticException("Division by 0!");
                   }
               } catch (NotIntegerException e) {
                   // ok
               }*/

			return JsclInteger.ONE.divide(parameter);
		} catch (NotDivisibleException e) {
		}

		return expressionValue();
	}

	public Generic parameter() {
		return parameters[1];
	}

	@Nonnull
	public Variable newInstance() {
		return new Inverse(null);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy