Divide

Divide( value_1, value_2, ... )
Divide( value_1, value_2, ... )
Divide( value_1, value_2, ... )
Divide( value_1, value_2, ... )
divide( value_1, value_2, ... )
Divide( value_1, value_2, ... )

Description

The Divide function computes the quotient of two or more numbers. When all of the numbers are integers, the result is a Long integer value. When any of the numbers is a floating-point number, the result is a Double-precision, floating-point value.

Attempting to Divide an empty list results in an "invalid argument" error.

Attempting to Divide any value by zero results in a "invalid argument" error.

Parameters

Parameter Type Definition and Requirements

value

Two or more Numbers to divide.

Returns

A Number which is the result of dividing two or more numbers. When all of the parameters are integers, the result is a Long (integer division). Otherwise, the result is a Double (floating-point division).

Examples

  1. The following query executes two equivalent division operations. The first example provides the Divide function a list of numbers. The second equivalent operation first divides 10 by 5, the takes the result of that operation and divides it by 2:

    try
    {
        Value result = await client.Query(
            Divide(10, 5, 2)
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    LongV(1)
    result, err := client.Query(
    	f.Divide(10, 5, 2))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    1
    System.out.println(
        client.query(
            Divide(Value(10), Value(5), Value(2))
        ).get());
    1
    client.query(
      q.Divide(10, 5, 2)
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    1
    result = client.query(
        q.divide(10, 5, 2)
    )
    print(result)
    1
    Divide(10, 5, 2)
    1
    Query metrics:
    •    bytesIn:  19

    •   bytesOut:  14

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 4ms

    •    retries:   0

    is equivalent to:

    try
    {
        Value result = await client.Query(
            Divide(Divide(10, 5), 2)
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    LongV(1)
    result, err := client.Query(
    	f.Divide(f.Divide(10, 5), 2))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    1
    System.out.println(
        client.query(
            Divide(Divide(Value(10), Value(5)), Value(2))
        ).get());
    1
    client.query(
      q.Divide(q.Divide(10, 5), 2)
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    1
    result = client.query(
        q.divide(q.divide(10, 5), 2)
    )
    print(result)
    1
    Divide(Divide(10, 5), 2)
    1
    Query metrics:
    •    bytesIn:  32

    •   bytesOut:  14

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 4ms

    •    retries:   0

  2. The following query demonstrates that dividing with integers results in an integer result:

    try
    {
        Value result = await client.Query(
            Divide(1, 2)
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    LongV(0)
    result, err := client.Query(
    	f.Divide(1, 2))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    0
    System.out.println(
        client.query(
            Divide(Value(1), Value(2))
        ).get());
    0
    client.query(
      q.Divide(1, 2)
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    0
    result = client.query(
        q.divide(1, 2)
    )
    print(result)
    0
    Divide(1, 2)
    0
    Query metrics:
    •    bytesIn:  16

    •   bytesOut:  14

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 2ms

    •    retries:   0

  3. The following query demonstrates that dividing with a double value results in a floating-point result:

    try
    {
        Value result = await client.Query(
            Divide(1, 2.0)
        );
        Console.WriteLine(result);
    }
    catch (Exception e)
    {
        Console.WriteLine($"ERROR: {e.Message}");
    }
    DoubleV(0.5)
    result, err := client.Query(
    	f.Divide(1, f.ToDouble(2)))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    0.5
    System.out.println(
        client.query(
            Divide(Value(1), ToDouble(Value(2)))
        ).get());
    0.5
    client.query(
      q.Divide(1, q.ToDouble(2))
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error(
      'Error: [%s] %s: %s',
      err.name,
      err.message,
      err.errors()[0].description,
    ))
    0.5
    result = client.query(
      q.divide(1, q.to_double(2))
    )
    print(result)
    0.5
    Divide(1, ToDouble(2))
    0.5
    Query metrics:
    •    bytesIn:  30

    •   bytesOut:  16

    • computeOps:   1

    •    readOps:   0

    •   writeOps:   0

    •  readBytes:   0

    • writeBytes:   0

    •  queryTime: 3ms

    •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!