Class MathExpressions
java.lang.Object
dev.morphia.aggregation.expressions.MathExpressions
Defines helper methods for the math expressions
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Expression
Returns the absolute value of a number.static Expression
Adds numbers together or adds numbers and a date.static Expression
Returns the result of a bitwise and operation on an array of int or long values.static Expression
Returns the result of a bitwise not operation on a single int or long value.static Expression
Returns the result of a bitwise or operation on an array of int or long values.static Expression
Returns the result of a bitwise xor operation on an array of int xor long values.static Expression
Returns the smallest integer greater than or equal to the specified number.static Expression
Returns the result of dividing the first number by the second.static Expression
Raises e to the specified exponent.static Expression
Returns the largest integer less than or equal to the specified number.static Expression
Calculates the natural log of a number.static Expression
Calculates the log of a number in the specified base.static Expression
Calculates the log base 10 of a number.static Expression
Returns an approximation of the median, the 50th percentile, as a scalar value.static Expression
Returns the remainder of the first number divided by the second.static Expression
Multiplies numbers together and returns the result.static Expression
percentile
(Object input, List<Object> percentiles) Returns an array of scalar values that correspond to specified percentile values.static Expression
percentile
(List<Object> inputs, List<Object> percentiles) Returns an array of scalar values that correspond to specified percentile values.static Expression
Raises a number to the specified exponent.static Expression
Rounds a number to a whole integer or to a specified decimal place.static Expression
Calculates the square root.static Expression
Returns the result of subtracting the second value from the first.static Expression
Truncates a number to a whole integer or to a specified decimal place.static Expression
Truncates a number to a whole integer or to a specified decimal place.
-
Method Details
-
abs
Returns the absolute value of a number.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $abs
-
add
Adds numbers together or adds numbers and a date. If one of the arguments is a date, $add treats the other arguments as milliseconds to add to the date.- Parameters:
first
- the first value to sumadditional
- any subsequent values to include in the sum- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $add
-
bitAnd
Returns the result of a bitwise and operation on an array of int or long values.- Parameters:
first
- the first value to usesecond
- the second value to use- Returns:
- the new expression
- Since:
- 3.0
- Since server release
- 6.3
- MongoDB documentation
- Aggregration Expression: $bitAnd
-
bitNot
Returns the result of a bitwise not operation on a single int or long value.- Parameters:
value
- the value to use- Returns:
- the new expression
- Since:
- 3.0
- Since server release
- 6.3
- MongoDB documentation
- Aggregration Expression: $bitNot
-
bitOr
Returns the result of a bitwise or operation on an array of int or long values.- Parameters:
first
- the first value to usesecond
- the second value to use- Returns:
- the new expression
- Since:
- 3.0
- Since server release
- 6.3
- MongoDB documentation
- Aggregration Expression: $bitOr
-
bitXor
Returns the result of a bitwise xor operation on an array of int xor long values.- Parameters:
first
- the first value to usesecond
- the second value to use- Returns:
- the new expression
- Since:
- 3.0
- Since server release
- 6.3
- MongoDB documentation
- Aggregration Expression: $bitXor
-
ceil
Returns the smallest integer greater than or equal to the specified number.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $ceil
-
divide
Returns the result of dividing the first number by the second. Accepts two argument expressions.- Parameters:
numerator
- the numeratordivisor
- the divisor- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $divide
-
exp
Raises e to the specified exponent.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $exp
-
floor
Returns the largest integer less than or equal to the specified number.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $floor
-
ln
Calculates the natural log of a number.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $ln
-
log
Calculates the log of a number in the specified base.- Parameters:
number
- the number to logbase
- the base to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $log
-
log10
Calculates the log base 10 of a number.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $log10
-
median
Returns an approximation of the median, the 50th percentile, as a scalar value.- Parameters:
input
- the input- Returns:
- the new expression
- Since:
- 3.0
- Since server release
- 7.0
- MongoDB documentation
- Aggregration Expression: $median
-
mod
Returns the remainder of the first number divided by the second. Accepts two argument expressions.- Parameters:
dividend
- the dividenddivisor
- the divisor- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $mod
-
multiply
Multiplies numbers together and returns the result. Pass the arguments to $multiply in an array.- Parameters:
first
- the first value to multiplyadditional
- any additional values- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $multiply
-
percentile
Returns an array of scalar values that correspond to specified percentile values.- Parameters:
input
- the input field or expressionpercentiles
- the percentiles to compute- Returns:
- the new expression
- Since:
- 3.0
- Since server release
- 7.0
- MongoDB documentation
- Aggregration Expression: $percentile
-
percentile
Returns an array of scalar values that correspond to specified percentile values.- Parameters:
inputs
- the input fields or expressionspercentiles
- the percentiles to compute- Returns:
- the new expression
- Since:
- 3.0
- Since server release
- 7.0
- MongoDB documentation
- Aggregration Expression: $percentile
-
pow
Raises a number to the specified exponent.- Parameters:
number
- the base nameexponent
- the exponent- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $pow
-
round
Rounds a number to a whole integer or to a specified decimal place.- Parameters:
number
- the valueplace
- the place to round to- Returns:
- the new expression
- Since server release
- 4.2
- MongoDB documentation
- Aggregration Expression: $round
-
sqrt
Calculates the square root.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $sqrt
-
subtract
Returns the result of subtracting the second value from the first. If the two values are numbers, return the difference. If the two values are dates, return the difference in milliseconds. If the two values are a date and a number in milliseconds, return the resulting date. Accepts two argument expressions. If the two values are a date and a number, specify the date argument first as it is not meaningful to subtract a date from a number.- Parameters:
minuend
- the number to subtract fromsubtrahend
- the number to subtract- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $subtract
-
trunc
Truncates a number to a whole integer or to a specified decimal place.NOTE: Prior to 4.2, the place value wasn't available. Pass null if your server is older than 4.2.
- Parameters:
number
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $trunc
-
trunc
Truncates a number to a whole integer or to a specified decimal place.NOTE: Prior to 4.2, the place value wasn't available. Use
trunc(Object)
if your server is older than 4.2.- Parameters:
number
- the valueplace
- the place to trunc to.- Returns:
- the new expression
- See Also:
- MongoDB documentation
- Aggregration Expression: $trunc
-