Function evaluate_divide

Source
pub fn evaluate_divide<'a>(
    arguments: &'a Vec<Unifiable>,
    ss: &'a Rc<SubstitutionSet<'a>>,
) -> Unifiable
Expand description

Divide the first argument by the following arguments.

If all the arguments are SIntegers, the function returns an SInteger.
If there is at least 1 SFloat in the list of argument, the function returns an SFloat.

If all the arguments are SIntegers, the function does an integer divide.
That is, all remainders are discarded:

7 / 3 => 2

This method is called by unify_sfunction().

§Arguments

§Returns

§Panics

  • If a logic variable in the list of terms is not grounded.
  • If one of the ground terms is not an SInteger or SFloat.

§Usage

use std::rc::Rc;
use suiron::*;

// Floating point division.
let ss = empty_ss!();
let arguments = parse_arguments("12.6, 3, 3").unwrap();
let result = evaluate_divide(&arguments, &ss);
println!("{}", result);
// Prints: 1.4000000000000001

// Integer division.
let ss = empty_ss!();
let arguments = parse_arguments("13, 3, 3").unwrap();
let result = evaluate_divide(&arguments, &ss);
println!("{}", result);
// Prints: 1