توابع حسابی

توابع حسابی

تمام توابع حسابی در Cloud Firestore رفتارهای زیر را دارند:

  • اگر هر یک از پارامترهای ورودی NULL باشد، مقدار NULL را ارزیابی می‌کند.
  • اگر هر یک از آرگومان‌ها NaN باشد، مقدار NaN را ارزیابی می‌کند.
  • اگر سرریز یا سرریز ناقص رخ دهد، خطا ایجاد می‌کند.

علاوه بر این، هنگامی که یک تابع حسابی چندین آرگومان عددی از انواع مختلف را دریافت می‌کند (برای مثال: add(5.0, 6)Cloud Firestore به طور ضمنی آرگومان‌ها را به وسیع‌ترین نوع ورودی تبدیل می‌کند. اگر فقط ورودی‌های INT32 ارائه شوند، نوع بازگشتی INT64 خواهد بود.

نام توضیحات
ABS قدر مطلق یک number را برمی‌گرداند
ADD مقدار x + y را برمی‌گرداند
SUBTRACT مقدار x - y را برمی‌گرداند
MULTIPLY مقدار x * y را برمی‌گرداند
DIVIDE مقدار x / y را برمی‌گرداند
MOD باقیمانده تقسیم x / y را برمی‌گرداند
CEIL سقف یک number را برمی‌گرداند
FLOOR حداقل یک number را برمی‌گرداند
ROUND یک number تا places اعشار گرد می‌کند
POW مقدار base^exponent برمی‌گرداند
SQRT جذر یک number را برمی‌گرداند
EXP عدد اویلر را به توان توان exponent می‌رساند.
LN لگاریتم طبیعی یک number را برمی‌گرداند
LOG لگاریتم یک number را برمی‌گرداند
LOG10 لگاریتم یک number را در مبنای 10 برمی‌گرداند
RAND یک عدد اعشاری شبه تصادفی برمی‌گرداند

ای بی اس

نحو:

abs[N <: INT32 | INT64 | FLOAT64](number: N) -> N

شرح:

قدر مطلق یک number را برمی‌گرداند.

  • وقتی تابع مقدار INT32 یا INT64 را سرریز می‌کند، خطا می‌دهد.

مثال‌ها:

شماره abs(number)
۱۰ ۱۰
-10 ۱۰
10 لیتر 10 لیتر
-0.0 ۰.۰
۱۰.۵ ۱۰.۵
-۱۰.۵ ۱۰.۵
۳۱ [error]
۶۳ [error]

اضافه کردن

نحو:

add[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x + y را برمی‌گرداند.

مثال‌ها:

ایکس ی add(x, y)
۲۰ ۳ ۲۳
۱۰.۰ ۱ ۱۱.۰
۲۲.۵ ۲.۰ ۲۴.۵
INT64.MAX ۱ [error]
INT64.MIN -1 [error]

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("soldBooks").add(field("unsoldBooks")).as("totalBooks"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("soldBooks").add(Field("unsoldBooks")).as("totalBooks")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.add(field("soldBooks"), field("unsoldBooks")).alias("totalBooks"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.add(field("soldBooks"), field("unsoldBooks")).alias("totalBooks"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("soldBooks").add(Field.of("unsoldBooks")).as_("totalBooks"))
    .execute()
)

تفریق

نحو:

subtract[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x - y را برمی‌گرداند.

مثال‌ها:

ایکس ی subtract(x, y)
۲۰ ۳ ۱۷
۱۰.۰ ۱ ۹.۰
۲۲.۵ ۲.۰ ۲۰.۵
INT64.MAX -1 [error]
INT64.MIN ۱ [error]

Web

const storeCredit = 7;
const result = await execute(db.pipeline()
  .collection("books")
  .select(field("price").subtract(constant(storeCredit)).as("totalCost"))
);
سویفت
let storeCredit = 7
let result = try await db.pipeline()
  .collection("books")
  .select([Field("price").subtract(Constant(storeCredit)).as("totalCost")])
  .execute()

Kotlin

val storeCredit = 7
val result = db.pipeline()
    .collection("books")
    .select(Expression.subtract(field("price"), storeCredit).alias("totalCost"))
    .execute()

Java

int storeCredit = 7;
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.subtract(field("price"), storeCredit).alias("totalCost"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

store_credit = 7
result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("price").subtract(store_credit).as_("totalCost"))
    .execute()
)

ضرب کردن

نحو:

multiply[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x * y را برمی‌گرداند.

مثال‌ها:

ایکس ی multiply(x, y)
۲۰ ۳ ۶۰
۱۰.۰ ۱ ۱۰.۰
۲۲.۵ ۲.۰ ۴۵.۰
INT64.MAX ۲ [error]
INT64.MIN ۲ [error]
FLOAT64.MAX FLOAT64.MAX +inf

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("price").multiply(field("soldBooks")).as("revenue"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("price").multiply(Field("soldBooks")).as("revenue")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("price"), field("soldBooks")).alias("revenue"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("price"), field("soldBooks")).alias("revenue"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("price").multiply(Field.of("soldBooks")).as_("revenue"))
    .execute()
)

تقسیم کردن

نحو:

divide[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

مقدار x / y را برمی‌گرداند. تقسیم عدد صحیح کوتاه شده است.

مثال‌ها:

ایکس ی divide(x, y)
۲۰ ۳ ۶
۱۰.۰ ۳ ۳.۳۳۳...
۲۲.۵ ۲ ۱۱.۲۵
۱۰ 0 [error]
۱.۰ ۰.۰ +inf
-۱.۰ ۰.۰ -inf

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("ratings").divide(field("soldBooks")).as("reviewRate"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("ratings").divide(Field("soldBooks")).as("reviewRate")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.divide(field("ratings"), field("soldBooks")).alias("reviewRate"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.divide(field("ratings"), field("soldBooks")).alias("reviewRate"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("ratings").divide(Field.of("soldBooks")).as_("reviewRate"))
    .execute()
)

وزارت دفاع

نحو:

mod[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

شرح:

باقیمانده x / y را برمی‌گرداند.

  • وقتی y برای انواع عدد صحیح ( INT64 ) صفر باشد، error می‌دهد.
  • وقتی y برای انواع اعشاری ( FLOAT64 ) صفر باشد، NaN را برمی‌گرداند.

مثال‌ها:

ایکس ی mod(x, y)
۲۰ ۳ ۲
-10 ۳ -1
۱۰ -3 ۱
-10 -3 -1
۱۰ ۱ 0
۲۲.۵ ۲ ۰.۵
۲۲.۵ ۰.۰ NaN
۲۵ 0 [error]

Web

const displayCapacity = 1000;
const result = await execute(db.pipeline()
  .collection("books")
  .select(field("unsoldBooks").mod(constant(displayCapacity)).as("warehousedBooks"))
);
سویفت
let displayCapacity = 1000
let result = try await db.pipeline()
  .collection("books")
  .select([Field("unsoldBooks").mod(Constant(displayCapacity)).as("warehousedBooks")])
  .execute()

Kotlin

val displayCapacity = 1000
val result = db.pipeline()
    .collection("books")
    .select(Expression.mod(field("unsoldBooks"), displayCapacity).alias("warehousedBooks"))
    .execute()

Java

int displayCapacity = 1000;
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.mod(field("unsoldBooks"), displayCapacity).alias("warehousedBooks"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

display_capacity = 1000
result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("unsoldBooks").mod(display_capacity).as_("warehousedBooks"))
    .execute()
)

سقف

نحو:

ceil[N <: INT32 | INT64 | FLOAT64](number: N) -> N

شرح:

کوچکترین مقدار صحیح که کمتر از number نباشد را برمی‌گرداند.

مثال‌ها:

شماره ceil(number)
۲۰ ۲۰
۱۰ ۱۰
0 0
۲۴ لیتر ۲۴ لیتر
-0.4 -0.0
۰.۴ ۱.۰
۲۲.۵ ۲۳.۰
+inf +inf
-inf -inf

Web

const booksPerShelf = 100;
const result = await execute(db.pipeline()
  .collection("books")
  .select(
    field("unsoldBooks").divide(constant(booksPerShelf)).ceil().as("requiredShelves")
  )
);
سویفت
let booksPerShelf = 100
let result = try await db.pipeline()
  .collection("books")
  .select([
    Field("unsoldBooks").divide(Constant(booksPerShelf)).ceil().as("requiredShelves")
  ])
  .execute()

Kotlin

val booksPerShelf = 100
val result = db.pipeline()
    .collection("books")
    .select(
        Expression.divide(field("unsoldBooks"), booksPerShelf).ceil().alias("requiredShelves")
    )
    .execute()

Java

int booksPerShelf = 100;
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(
        Expression.divide(field("unsoldBooks"), booksPerShelf).ceil().alias("requiredShelves")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

books_per_shelf = 100
result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("unsoldBooks")
        .divide(books_per_shelf)
        .ceil()
        .as_("requiredShelves")
    )
    .execute()
)

طبقه

نحو:

floor[N <: INT32 | INT64 | FLOAT64](number: N) -> N

شرح:

بزرگترین مقدار صحیح که بزرگتر از number نباشد را برمی‌گرداند.

مثال‌ها:

شماره floor(number)
۲۰ ۲۰
۱۰ ۱۰
0 0
۲۱۴۷۴۸۳۶۴۸ ۲۱۴۷۴۸۳۶۴۸
-0.4 -۱.۰
۰.۴ ۰.۰
۲۲.۵ ۲۲.۰
+inf +inf
-inf -inf

Web

const result = await execute(db.pipeline()
  .collection("books")
  .addFields(
    field("wordCount").divide(field("pages")).floor().as("wordsPerPage")
  )
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .addFields([
    Field("wordCount").divide(Field("pages")).floor().as("wordsPerPage")
  ])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .addFields(
        Expression.divide(field("wordCount"), field("pages")).floor().alias("wordsPerPage")
    )
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .addFields(
        Expression.divide(field("wordCount"), field("pages")).floor().alias("wordsPerPage")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .add_fields(
        Field.of("wordCount").divide(Field.of("pages")).floor().as_("wordsPerPage")
    )
    .execute()
)

گرد

نحو:

round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> N
round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N, places: INT64) -> N

شرح:

places یک number را گرد می‌کند. اگر places مثبت باشد، ارقام را از سمت راست و اگر منفی باشد، ارقام را از سمت چپ گرد می‌کند.

  • اگر فقط number ارائه شده باشد، به نزدیکترین مقدار کامل گرد می‌شود.
  • در حالت‌های بینابینی، از صفر به سمت دور گرد می‌کند.
  • اگر گرد کردن با places منفی منجر به سرریز شود، error رخ می‌دهد.

مثال‌ها:

شماره مکان‌ها round(number, places)
۱۵.۵ 0 ۱۶.۰
-۱۵.۵ 0 -۱۶.۰
۱۵ ۱ ۱۵
۱۵ 0 ۱۵
۱۵ -1 ۲۰
۱۵ 0
۱۵.۴۸۹۲۴ ۱ ۱۵.۵
۲ ۳۱ -1 [error]
۲ ۶۳ -۱ لیتر -1 [error]

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("soldBooks").multiply(field("price")).round().as("partialRevenue"))
  .aggregate(field("partialRevenue").sum().as("totalRevenue"))
  );
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("soldBooks").multiply(Field("price")).round().as("partialRevenue")])
  .aggregate([Field("partialRevenue").sum().as("totalRevenue")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("soldBooks"), field("price")).round().alias("partialRevenue"))
    .aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(Expression.multiply(field("soldBooks"), field("price")).round().alias("partialRevenue"))
    .aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(
        Field.of("soldBooks")
        .multiply(Field.of("price"))
        .round()
        .as_("partialRevenue")
    )
    .aggregate(Field.of("partialRevenue").sum().as_("totalRevenue"))
    .execute()
)

صدای انفجار

نحو:

pow(base: FLOAT64, exponent: FLOAT64) -> FLOAT64

شرح:

مقدار base را که به توان exponent رسیده است، برمی‌گرداند.

  • اگر base <= 0 و exponent منفی باشد، خطا می‌دهد.

  • برای هر exponent ، pow(1, exponent) برابر با ۱ است.

  • برای هر base ، pow(base, 0) برابر با ۱ است.

مثال‌ها:

پایه توان pow(base, exponent)
۲ ۳ ۸.۰
۲ -3 ۰.۱۲۵
+inf 0 ۱.۰
۱ +inf ۱.۰
-1 ۰.۵ [error]
0 -1 [error]

Web

const googleplex = { latitude: 37.4221, longitude: 122.0853 };
const result = await execute(db.pipeline()
  .collection("cities")
  .addFields(
    field("lat").subtract(constant(googleplex.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    field("lng").subtract(constant(googleplex.longitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  )
  .select(
    field("latitudeDifference").add(field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  )
);
سویفت
let googleplex = CLLocation(latitude: 37.4221, longitude: 122.0853)
let result = try await db.pipeline()
  .collection("cities")
  .addFields([
    Field("lat").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    Field("lng").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  ])
  .select([
    Field("latitudeDifference").add(Field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  ])
  .execute()

Kotlin

val googleplex = GeoPoint(37.4221, -122.0853)
val result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.latitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.longitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute()

Java

GeoPoint googleplex = new GeoPoint(37.4221, -122.0853);
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.getLatitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.getLongitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

googleplexLat = 37.4221
googleplexLng = -122.0853
result = (
    client.pipeline()
    .collection("cities")
    .add_fields(
        Field.of("lat")
        .subtract(googleplexLat)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("latitudeDifference"),
        Field.of("lng")
        .subtract(googleplexLng)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("longitudeDifference"),
    )
    .select(
        Field.of("latitudeDifference")
        .add(Field.of("longitudeDifference"))
        .sqrt()
        # Inaccurate for large distances or close to poles
        .as_("approximateDistanceToGoogle")
    )
    .execute()
)

اس کیو آر تی

نحو:

sqrt[N <: FLOAT64 | DECIMAL128](number: N) -> N

شرح:

جذر یک number را برمی‌گرداند.

  • اگر number منفی باشد، error می‌دهد.

مثال‌ها:

شماره sqrt(number)
۲۵ ۵.۰
۱۲.۰۰۲ ۳.۴۶۴...
۰.۰ ۰.۰
NaN NaN
+inf +inf
-inf [error]
x < 0 [error]

Web

const googleplex = { latitude: 37.4221, longitude: 122.0853 };
const result = await execute(db.pipeline()
  .collection("cities")
  .addFields(
    field("lat").subtract(constant(googleplex.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    field("lng").subtract(constant(googleplex.longitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  )
  .select(
    field("latitudeDifference").add(field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  )
);
سویفت
let googleplex = CLLocation(latitude: 37.4221, longitude: 122.0853)
let result = try await db.pipeline()
  .collection("cities")
  .addFields([
    Field("lat").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("latitudeDifference"),
    Field("lng").subtract(Constant(googleplex.coordinate.latitude))
      .multiply(111 /* km per degree */)
      .pow(2)
      .as("longitudeDifference")
  ])
  .select([
    Field("latitudeDifference").add(Field("longitudeDifference")).sqrt()
      // Inaccurate for large distances or close to poles
      .as("approximateDistanceToGoogle")
  ])
  .execute()

Kotlin

val googleplex = GeoPoint(37.4221, -122.0853)
val result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.latitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.longitude)
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute()

Java

GeoPoint googleplex = new GeoPoint(37.4221, -122.0853);
Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("cities")
    .addFields(
        field("lat").subtract(googleplex.getLatitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("latitudeDifference"),
        field("lng").subtract(googleplex.getLongitude())
            .multiply(111 /* km per degree */)
            .pow(2)
            .alias("longitudeDifference")
    )
    .select(
        field("latitudeDifference").add(field("longitudeDifference")).sqrt()
            // Inaccurate for large distances or close to poles
            .alias("approximateDistanceToGoogle")
    )
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

googleplexLat = 37.4221
googleplexLng = -122.0853
result = (
    client.pipeline()
    .collection("cities")
    .add_fields(
        Field.of("lat")
        .subtract(googleplexLat)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("latitudeDifference"),
        Field.of("lng")
        .subtract(googleplexLng)
        .multiply(111)  # km per degree
        .pow(2)
        .as_("longitudeDifference"),
    )
    .select(
        Field.of("latitudeDifference")
        .add(Field.of("longitudeDifference"))
        .sqrt()
        # Inaccurate for large distances or close to poles
        .as_("approximateDistanceToGoogle")
    )
    .execute()
)

تاریخ انقضا

نحو:

exp(exponent: FLOAT64) -> FLOAT64

شرح:

مقدار عدد اویلر را که به توان exponent رسیده است، برمی‌گرداند. این تابع، تابع نمایی طبیعی نیز نامیده می‌شود.

مثال‌ها:

توان exp(exponent)
۰.۰ ۱.۰
۱۰ e^10 ( FLOAT64 )
+inf +inf
-inf 0

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").exp().as("expRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").exp().as("expRating")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("rating").exp().alias("expRating"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").exp().alias("expRating"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").exp().as_("expRating"))
    .execute()
)

ال ان

نحو:

ln(number: FLOAT64) -> FLOAT64

شرح:

لگاریتم طبیعی number را برمی‌گرداند. این تابع معادل تابع log(number) است.

مثال‌ها:

شماره ln(number)
۱ ۰.۰
۲ لیتر ۰.۶۹۳...
۱.۰ ۰.۰
e ( FLOAT64 ) ۱.۰
-inf NaN
+inf +inf
x <= 0 [error]

Web

const result = await execute(db.pipeline()
  .collection("books")
  .select(field("rating").ln().as("lnRating"))
);
سویفت
let result = try await db.pipeline()
  .collection("books")
  .select([Field("rating").ln().as("lnRating")])
  .execute()

Kotlin

val result = db.pipeline()
    .collection("books")
    .select(field("rating").ln().alias("lnRating"))
    .execute()

Java

Task<Pipeline.Snapshot> result = db.pipeline()
    .collection("books")
    .select(field("rating").ln().alias("lnRating"))
    .execute();
    
پایتون
from google.cloud.firestore_v1.pipeline_expressions import Field

result = (
    client.pipeline()
    .collection("books")
    .select(Field.of("rating").ln().as_("lnRating"))
    .execute()
)

ورود به سیستم

نحو:

log(number: FLOAT64, base: FLOAT64) -> FLOAT64
log(number: FLOAT64) -> FLOAT64

شرح:

لگاریتم یک number را به base برمی‌گرداند.

  • اگر فقط number ارائه شده باشد، لگاریتم number را در base برمی‌گرداند (مترادف با ln(number) ).

مثال‌ها:

شماره پایه log(number, base)
۱۰۰ ۱۰ ۲.۰
-inf Numeric NaN
Numeric +inf NaN
number <= 0 Numeric [error]
Numeric base <= 0 [error]
Numeric ۱.۰ [error]

لاگ10

نحو:

log10(x: FLOAT64) -> FLOAT64

شرح:

لگاریتم یک number در مبنای 10 را برمی‌گرداند.

مثال‌ها:

شماره log10(number)
۱۰۰ ۲.۰
-inf NaN
+inf +inf
x <= 0 [error]

رند

نحو:

rand() -> FLOAT64

شرح:

یک عدد اعشاری شبه‌تصادفی را برمی‌گرداند که به طور یکنواخت بین 0.0 (شامل) و 1.0 (منحصراً) انتخاب شده است.