@@ -1917,8 +1917,43 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
19171917 *
19181918 * @return A new `Expr` representing the rounded value.
19191919 */
1920- round ( ) : FunctionExpression {
1921- return new FunctionExpression ( 'round' , [ this ] ) ;
1920+ round ( ) : FunctionExpression ;
1921+ /**
1922+ * Creates an expression that rounds a numeric value to the specified number of decimal places.
1923+ *
1924+ * ```typescript
1925+ * // Round the value of the 'price' field to two decimal places.
1926+ * field("price").round(2);
1927+ * ```
1928+ *
1929+ * @param decimalPlaces A constant specifying the rounding precision in decimal places.
1930+ *
1931+ * @return A new `Expr` representing the rounded value.
1932+ */
1933+ round ( decimalPlaces : number ) : FunctionExpression ;
1934+ /**
1935+ * Creates an expression that rounds a numeric value to the specified number of decimal places.
1936+ *
1937+ * ```typescript
1938+ * // Round the value of the 'price' field to two decimal places.
1939+ * field("price").round(constant(2));
1940+ * ```
1941+ *
1942+ * @param decimalPlaces An expression specifying the rounding precision in decimal places.
1943+ *
1944+ * @return A new `Expr` representing the rounded value.
1945+ */
1946+ round ( decimalPlaces : Expression ) : FunctionExpression ;
1947+ round ( decimalPlaces ?: number | Expression ) : FunctionExpression {
1948+ if ( decimalPlaces === undefined ) {
1949+ return new FunctionExpression ( 'round' , [ this ] ) ;
1950+ } else {
1951+ return new FunctionExpression (
1952+ 'round' ,
1953+ [ this , valueToDefaultExpr ( decimalPlaces ) ] ,
1954+ 'round'
1955+ ) ;
1956+ }
19221957 }
19231958
19241959 /**
@@ -1966,35 +2001,6 @@ export abstract class Expression implements ProtoValueSerializable, UserData {
19662001 return new FunctionExpression ( 'ln' , [ this ] ) ;
19672002 }
19682003
1969- /**
1970- * Creates an expression that computes the logarithm of this expression to a given base.
1971- *
1972- * ```typescript
1973- * // Compute the logarithm of the 'value' field with base 10.
1974- * field("value").log(10);
1975- * ```
1976- *
1977- * @param base The base of the logarithm.
1978- * @return A new {@code Expr} representing the logarithm of the numeric value.
1979- */
1980- log ( base : number ) : FunctionExpression ;
1981-
1982- /**
1983- * Creates an expression that computes the logarithm of this expression to a given base.
1984- *
1985- * ```typescript
1986- * // Compute the logarithm of the 'value' field with the base in the 'base' field.
1987- * field("value").log(field("base"));
1988- * ```
1989- *
1990- * @param base The base of the logarithm.
1991- * @return A new {@code Expr} representing the logarithm of the numeric value.
1992- */
1993- log ( base : Expression ) : FunctionExpression ;
1994- log ( base : number | Expression ) : FunctionExpression {
1995- return new FunctionExpression ( 'log' , [ this , valueToDefaultExpr ( base ) ] ) ;
1996- }
1997-
19982004 /**
19992005 * Creates an expression that computes the square root of a numeric value.
20002006 *
@@ -6876,8 +6882,49 @@ export function round(fieldName: string): FunctionExpression;
68766882 * @return A new `Expr` representing the rounded value.
68776883 */
68786884export function round ( expression : Expression ) : FunctionExpression ;
6879- export function round ( expr : Expression | string ) : FunctionExpression {
6880- return fieldOrExpression ( expr ) . round ( ) ;
6885+
6886+ /**
6887+ * Creates an expression that rounds a numeric value to the specified number of decimal places.
6888+ *
6889+ * ```typescript
6890+ * // Round the value of the 'price' field to two decimal places.
6891+ * round("price", 2);
6892+ * ```
6893+ *
6894+ * @param fieldName The name of the field to round.
6895+ * @param decimalPlaces A constant or expression specifying the rounding precision in decimal places.
6896+ * @return A new `Expr` representing the rounded value.
6897+ */
6898+ export function round (
6899+ fieldName : string ,
6900+ decimalPlaces : number | Expression
6901+ ) : FunctionExpression ;
6902+
6903+ /**
6904+ * Creates an expression that rounds a numeric value to the specified number of decimal places.
6905+ *
6906+ * ```typescript
6907+ * // Round the value of the 'price' field to two decimal places.
6908+ * round(field("price"), constant(2));
6909+ * ```
6910+ *
6911+ * @param expression An expression evaluating to a numeric value, which will be rounded.
6912+ * @param decimalPlaces A constant or expression specifying the rounding precision in decimal places.
6913+ * @return A new `Expr` representing the rounded value.
6914+ */
6915+ export function round (
6916+ expression : Expression ,
6917+ decimalPlaces : number | Expression
6918+ ) : FunctionExpression ;
6919+ export function round (
6920+ expr : Expression | string ,
6921+ decimalPlaces ?: number | Expression
6922+ ) : FunctionExpression {
6923+ if ( decimalPlaces === undefined ) {
6924+ return fieldOrExpression ( expr ) . round ( ) ;
6925+ } else {
6926+ return fieldOrExpression ( expr ) . round ( valueToDefaultExpr ( decimalPlaces ) ) ;
6927+ }
68816928}
68826929
68836930/**
@@ -7032,7 +7079,10 @@ export function log(
70327079 expr : Expression | string ,
70337080 base : number | Expression
70347081) : FunctionExpression {
7035- return fieldOrExpression ( expr ) . log ( valueToDefaultExpr ( base ) ) ;
7082+ return new FunctionExpression ( 'log' , [
7083+ fieldOrExpression ( expr ) ,
7084+ valueToDefaultExpr ( base )
7085+ ] ) ;
70367086}
70377087
70387088/**
0 commit comments