Add support for float numbers in rem() arguments (#4858)
* Add support for float numbers in rem() arguments * Update docs * Rename to prevent name collision in docs * Update docs after rename to NumberArg * Fix parameter types to follow naming convention * Change doc comment description to not refer to floating point * Update docs after NumberArg doc change * Change function to be more condensed * Change to not try to preserve ints * Update docs to use f64 * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-macos-8-cores) * Trigger CI --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -322,15 +322,6 @@ impl Args {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn make_user_val_from_i64(&self, n: i64) -> KclValue {
|
||||
KclValue::Int {
|
||||
value: n,
|
||||
meta: vec![Metadata {
|
||||
source_range: self.source_range,
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn make_user_val_from_f64_array(&self, f: Vec<f64>) -> Result<KclValue, KclError> {
|
||||
let array = f
|
||||
.into_iter()
|
||||
|
||||
@ -16,9 +16,9 @@ use super::args::FromArgs;
|
||||
pub async fn rem(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let n = args.get_unlabeled_kw_arg("number to divide")?;
|
||||
let d = args.get_kw_arg("divisor")?;
|
||||
let result = inner_rem(n, d)?;
|
||||
let remainder = inner_rem(n, d);
|
||||
|
||||
Ok(args.make_user_val_from_i64(result))
|
||||
Ok(args.make_user_val_from_f64(remainder))
|
||||
}
|
||||
|
||||
/// Compute the remainder after dividing `num` by `div`.
|
||||
@ -28,6 +28,9 @@ pub async fn rem(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
|
||||
/// assertEqual(rem( 7, divisor = 4), 3, 0.01, "remainder is 3" )
|
||||
/// assertEqual(rem(-7, divisor = 4), -3, 0.01, "remainder is -3")
|
||||
/// assertEqual(rem( 7, divisor = -4), 3, 0.01, "remainder is 3" )
|
||||
/// assertEqual(rem( 6, divisor = 2.5), 1, 0.01, "remainder is 1" )
|
||||
/// assertEqual(rem( 6.5, divisor = 2.5), 1.5, 0.01, "remainder is 1.5" )
|
||||
/// assertEqual(rem( 6.5, divisor = 2), 0.5, 0.01, "remainder is 0.5" )
|
||||
/// ```
|
||||
#[stdlib {
|
||||
name = "rem",
|
||||
@ -39,8 +42,8 @@ pub async fn rem(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kc
|
||||
divisor = "The number which will divide `num`.",
|
||||
}
|
||||
}]
|
||||
fn inner_rem(num: i64, divisor: i64) -> Result<i64, KclError> {
|
||||
Ok(num % divisor)
|
||||
fn inner_rem(num: f64, divisor: f64) -> f64 {
|
||||
num % divisor
|
||||
}
|
||||
|
||||
/// Compute the cosine of a number (in radians).
|
||||
|
||||
Reference in New Issue
Block a user