Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for BigInteger and BigDecimal #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion pmml-evaluator/src/main/java/org/jpmml/evaluator/TypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.jpmml.evaluator;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -579,6 +581,10 @@ private Integer toInteger(Object value){

return Integer.valueOf(number.intValue());
}

if(value instanceof BigInteger) {
return ((BigInteger)value).intValue();
}

throw new TypeCheckException(DataType.INTEGER, value);
}
Expand Down Expand Up @@ -630,6 +636,14 @@ private Float toFloat(Object value){

return toFloat(number.floatValue());
}

if(value instanceof BigInteger) {
return ((BigInteger)value).floatValue();
}

if(value instanceof BigDecimal) {
return ((BigDecimal)value).floatValue();
}

throw new TypeCheckException(DataType.FLOAT, value);
}
Expand Down Expand Up @@ -683,6 +697,14 @@ private Double toDouble(Object value){

return toDouble(number.doubleValue());
}

if(value instanceof BigInteger) {
return ((BigInteger)value).doubleValue();
}

if(value instanceof BigDecimal) {
return ((BigDecimal)value).doubleValue();
}

throw new TypeCheckException(DataType.DOUBLE, value);
}
Expand Down Expand Up @@ -903,4 +925,4 @@ private DataType getSecondsDataType(LocalDate epoch){

throw new EvaluationException("Non-standard epoch " + epoch);
}
}
}