arithmetic

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package arithmetic Arithmetic expressions perform mathematic operations on numbers. Some arithmetic expressions can also support date arithmetic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T expression.NumberExpression](number T) arithmeticOperator

Abs Returns the absolute value of a number. $abs has the following syntax: { $abs: <number> } The <number> expression can be any valid expression as long as it resolves to a number.

func Add

func Add[T expression.DateNumberExpression](n []T) arithmeticOperator

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. The $add expression has the following syntax: { $add: [ <expression1>, <expression2>, ... ] } The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date.

func Ceil

func Ceil[T expression.NumberExpression](n T) arithmeticOperator

Ceil Returns the smallest integer greater than or equal to the specified number. $ceil has the following syntax: { $ceil: <number> } The <number> expression can be any valid expression as long as it resolves to a number.

func Divide

func Divide[T expression.NumberExpression](n1, n2 T) arithmeticOperator

Divide Divides one number by another and returns the result. Pass the arguments to $divide in an array. The $divide expression has the following syntax: { $divide: [ <expression1>, <expression2> ] } The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. The arguments can be any valid expression as long as they resolve to numbers.

func Exp

func Exp[T expression.NumberExpression](n T) arithmeticOperator

Exp Raises Euler's number (i.e. e ) to the specified exponent and returns the result. $exp has the following syntax: { $exp: <exponent> } The <exponent> expression can be any valid expression as long as it resolves to a number

func Floor

func Floor[T expression.NumberExpression](n T) arithmeticOperator

Floor Returns the largest integer less than or equal to the specified number. $floor has the following syntax: { $floor: <number> } The <number> expression can be any valid expression as long as it resolves to a number.

func Ln

func Ln[T expression.NumberExpression](n T) arithmeticOperator

Ln Calculates the natural logarithm ln (i.e log e) of a number and returns the result as a double. $ln has the following syntax: { $ln: <number> } The <number> expression can be any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. $ln is equivalent to $log: [ <number>, Math.E ] expression, where Math.E is a JavaScript representation for Euler's number e.

func Log

func Log[T expression.NumberExpression](n, base T) arithmeticOperator

Log Calculates the log of a number in the specified base and returns the result as a double. $log has the following syntax: { $log: [ <number>, <base> ] } The <number> expression can be any valid expression as long as it resolves to a non-negative number. The <base> expression can be any valid expression as long as it resolves to a positive number greater than 1.

func Log10

func Log10[T expression.NumberExpression](n T) arithmeticOperator

Log10 Calculates the log base 10 of a number and returns the result as a double. $log10 has the following syntax: { $log10: <number> } The <number> expression can be any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. $log10 is equivalent to $log: [ <number>, 10 ] expression.

func Mod

func Mod[T expression.NumberExpression](n1, n2 T) arithmeticOperator

Mod Divides one number by another and returns the remainder. The $mod expression has the following syntax: { $mod: [ <expression1>, <expression2> ] } The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. The arguments can be any valid expression as long as they resolve to numbers.

func Multiply

func Multiply[T expression.NumberExpression](ns []T) arithmeticOperator

Multiply Multiplies numbers together and returns the result. Pass the arguments to $multiply in an array. The $multiply expression has the following syntax: { $multiply: [ <expression1>, <expression2>, ... ] } The arguments can be any valid expression as long as they resolve to numbers.

func Pow

func Pow[T expression.NumberExpression](n, e T) arithmeticOperator

Pow Raises a number to the specified exponent and returns the result. $pow has the following syntax: { $pow: [ <number>, <exponent> ] } The <number> expression can be any valid expression as long as it resolves to a number. The <exponent> expression can be any valid expression as long as it resolves to a number. You cannot raise 0 to a negative exponent.

func Round

func Round[N expression.NumberExpression, I expression.IntExpression](n N, p I) arithmeticOperator

Round New in version 4.2. $round rounds a number to a whole integer or to a specified decimal place. $round has the following syntax: { $round : [ <number>, <place> ] }

func Sqrt

func Sqrt[T expression.NumberExpression](n T) arithmeticOperator

Sqrt Calculates the square root of a positive number and returns the result as a double. $sqrt has the following syntax: { $sqrt: <number> } The argument can be any valid expression as long as it resolves to a non-negative number

func Subtract

func Subtract[N expression.DateNumberExpression](n1, n2 N) arithmeticOperator

Subtract Subtracts two numbers to return the difference, or two dates to return the difference in milliseconds, or a date and a number in milliseconds to return the resulting date. The $subtract expression has the following syntax: { $subtract: [ <expression1>, <expression2> ] } The second argument is subtracted from the first argument. The arguments can be any valid expression as long as they resolve to numbers and/or dates. To subtract a number from a date, the date must be the first argument.

func Trunc

func Trunc[N expression.NumberExpression, I expression.IntExpression](n N, p I) arithmeticOperator

Trunc Changed in version 4.2.. $trunc truncates a number to a whole integer or to a specified decimal place. MongoDB 4.2 adds the following syntax for $trunc: { $trunc : [ <number>, <place> ] }

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL