package jetbrains.mps.baseLanguage.math.runtime;

/*Generated by MPS */

import java.math.MathContext;
import java.math.BigInteger;
import java.math.BigDecimal;

public class BigComplexScalarOperations implements MatrixScalarOperations {
  /*package*/ MathContext myContext = null;
  public BigComplexScalarOperations() {
  }
  public BigComplexScalarOperations(MathContext context) {
    myContext = context;
  }
  @Override
  public BigComplex cast(Object o) {
    if (o instanceof BigComplex) {
      return (BigComplex) o;
    }
    if (o instanceof Complex) {
      return new BigComplex((Complex) o);
    }
    if (o instanceof BigInteger) {
      return new BigComplex(new BigDecimal((BigInteger) o), BigDecimal.ZERO);
    }
    if (o instanceof BigDecimal) {
      return new BigComplex(((BigDecimal) o), BigDecimal.ZERO);
    }
    if (o instanceof Number) {
      return new BigComplex(((Number) o).doubleValue(), 0);
    }
    throw new ClassCastException();
  }
  @Override
  public BigComplex add(Object o1, Object o2) {
    if (myContext == null) {
      return cast(o1).add(cast(o2));
    } else
    return cast(o1).add(cast(o2), myContext);
  }
  @Override
  public BigComplex mul(Object i1, Object o2) {
    if (myContext == null) {
      return cast(i1).mul(cast(o2));
    } else
    return cast(i1).mul(cast(o2), myContext);
  }
  @Override
  public BigComplex neg(Object i) {
    BigComplex c = cast(i);
    return new BigComplex(c.re().negate(), c.im().negate());
  }
  @Override
  public BigComplex inv(Object d) {
    if (myContext == null) {
      return cast(d).inv();
    } else
    return cast(d).inv(myContext);
  }
  @Override
  public BigComplex conj(Object o) {
    return cast(o).conj();
  }
  @Override
  public Object abs(Object o) {
    return cast(o).abs(myContext);
  }
}
