protected double doFunction(double a) {
// Copied from RubyMath - see copyright notices there
if (a == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("gamma", this));
}
if (Double.isNaN(a)) {
return Double.NaN;
}
if (Double.isInfinite(a)) {
if (a > 0) {
return Double.POSITIVE_INFINITY;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("gamma", this));
}
}
double result = RubyMath.nemes_gamma(a);
if (Double.isInfinite(result)) {
if (a < 0) {
result = Double.NaN;
} else {
if (a == 0 && 1 / a < 0) {
result = Double.NEGATIVE_INFINITY;
} else {
result = Double.POSITIVE_INFINITY;
}
}
}
if (Double.isNaN(a)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("gamma", this));
}
return result;
}