/* Result is the numeric value of the smallest value. */ public static SchemaTypeNumber min(SchemaTypeNumber value1, SchemaTypeNumber value2) { switch (java.lang.Math.max(value1.numericType(), value2.numericType())) { case SchemaTypeNumber.NUMERIC_VALUE_INT: return new SchemaInt(java.lang.Math.min(value1.intValue(), value2.intValue())); case SchemaTypeNumber.NUMERIC_VALUE_LONG: return new SchemaLong(java.lang.Math.min(value1.longValue(), value2.longValue())); case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER: return new SchemaInteger(value1.bigIntegerValue().min(value2.bigIntegerValue())); case SchemaTypeNumber.NUMERIC_VALUE_FLOAT: return new SchemaFloat(java.lang.Math.min(value1.floatValue(), value2.floatValue())); case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE: return new SchemaDouble(java.lang.Math.min(value1.doubleValue(), value2.doubleValue())); } return new SchemaDecimal(value1.bigDecimalValue().min(value2.bigDecimalValue())); }
protected static SchemaType getCommonNumberInstance(SchemaType a_value, SchemaType b) { return (SchemaType) getCommonNumberInstance( java.lang.Math.max( ((SchemaTypeNumber) a_value).numericType(), ((SchemaTypeNumber) b).numericType()), (SchemaTypeNumber) a_value); }
protected static SchemaType getCommonCalendarInstance(SchemaType a_value, SchemaType b) { switch (java.lang.Math.max( ((SchemaTypeCalendar) a_value).calendarType(), ((SchemaTypeCalendar) b).calendarType())) { case SchemaTypeCalendar.CALENDAR_VALUE_DURATION: return new SchemaDuration(((SchemaTypeCalendar) a_value).durationValue()); case SchemaTypeCalendar.CALENDAR_VALUE_DATETIME: return new SchemaDateTime(((SchemaTypeCalendar) a_value).dateTimeValue()); case SchemaTypeCalendar.CALENDAR_VALUE_DATE: return new SchemaDate(((SchemaTypeCalendar) a_value).dateValue()); case SchemaTypeCalendar.CALENDAR_VALUE_TIME: return new SchemaTime(((SchemaTypeCalendar) a_value).timeValue()); } throw new ValuesNotConvertableException(a_value, b); }
/* Returns the value of a raised to the power of b. */ public static SchemaTypeNumber pow(SchemaTypeNumber a, SchemaTypeNumber b) { switch (java.lang.Math.max(a.numericType(), b.numericType())) { case SchemaTypeNumber.NUMERIC_VALUE_INT: return new SchemaInt((int) java.lang.Math.pow(a.doubleValue(), b.doubleValue())); case SchemaTypeNumber.NUMERIC_VALUE_LONG: return new SchemaLong((long) java.lang.Math.pow(a.doubleValue(), b.doubleValue())); case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER: return new SchemaInteger((long) java.lang.Math.pow(a.doubleValue(), b.doubleValue())); case SchemaTypeNumber.NUMERIC_VALUE_FLOAT: return new SchemaFloat((float) java.lang.Math.pow(a.doubleValue(), b.doubleValue())); case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE: return new SchemaDouble(java.lang.Math.pow(a.doubleValue(), b.doubleValue())); } return new SchemaDecimal(java.lang.Math.pow(a.doubleValue(), b.doubleValue())); }
/* Returns the correctly rounded positive square root of a value. */ public static SchemaTypeNumber sqrt(SchemaTypeNumber value) { switch (value.numericType()) { case SchemaTypeNumber.NUMERIC_VALUE_INT: return new SchemaInt((int) java.lang.Math.sqrt(value.doubleValue())); case SchemaTypeNumber.NUMERIC_VALUE_LONG: return new SchemaLong((long) java.lang.Math.sqrt(value.doubleValue())); case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER: return new SchemaInteger( (long) java.lang.Math.sqrt(value.doubleValue())); // note: possible loss of precision case SchemaTypeNumber.NUMERIC_VALUE_FLOAT: return new SchemaFloat((float) java.lang.Math.sqrt(value.doubleValue())); case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE: return new SchemaDouble(java.lang.Math.sqrt(value.doubleValue())); } return new SchemaDecimal(java.lang.Math.sqrt(value.doubleValue())); }
/* Returns a value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range. */ public static SchemaTypeNumber random() { return new SchemaDouble(java.lang.Math.random()); }