Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Math methods #514

Closed
HalidOdat opened this issue Jun 19, 2020 · 7 comments · Fixed by #523
Closed

Cleanup Math methods #514

HalidOdat opened this issue Jun 19, 2020 · 7 comments · Fixed by #523
Assignees
Labels
builtins PRs and Issues related to builtins/intrinsics E-Easy Easy good first issue Good for newcomers technical debt
Milestone

Comments

@HalidOdat
Copy link
Member

Many of the Math builtin functions are a bit convoluted for example:

pub(crate) fn abs(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
    Ok(Value::from(if args.is_empty() {
       f64::NAN
    } else {
        f64::from(args.get(0).expect("Could not get argument")).abs()
    }))
}

This is also inefficient because we check if there is an argument and then another check is done when we call .expect().

A better way of doing this would be to use .map_or which would simplify the code a lot:

pub(crate) fn abs(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
	Ok(args.get(0).map_or(f64::NAN, |x| f64::from(x).abs()).into())
}
@HalidOdat HalidOdat added good first issue Good for newcomers E-Easy Easy technical debt builtins PRs and Issues related to builtins/intrinsics labels Jun 19, 2020
@n14little
Copy link
Contributor

I’ll take this

@HalidOdat
Copy link
Member Author

I’ll take this

Sure!

@n14little
Copy link
Contributor

@HalidOdat There are still some methods that can be cleaned up in this issue. I just did the ones that were quick and easy.

@HalidOdat
Copy link
Member Author

@HalidOdat There are still some methods that can be cleaned up in this issue. I just did the ones that were quick and easy.

In that case, I'll reopen the issue :)

@HalidOdat HalidOdat reopened this Jun 23, 2020
@pedropaulosuzuki
Copy link
Contributor

pedropaulosuzuki commented Jun 23, 2020

In that case, we might benefit from mapping which methods still need refactoring:

  • Math.abs()
  • Math.acos()
  • Math.acosh()
  • Math.asin()
  • Math.asinh()
  • Math.atan()
  • Math.atan2()
  • Math.atanh()
  • Math.cbrt()
  • Math.ceil()
  • Math.clz32()
  • Math.cos()
  • Math.cosh()
  • Math.exp()
  • Math.expm1()
  • Math.floor()
  • Math.fround()
  • Math.hypot()
  • Math.imul()
  • Math.log()
  • Math.log10()
  • Math.log1p()
  • Math.log2()
  • Math.max()
  • Math.min()
  • Math.pow()
  • Math.random()
  • Math.round()
  • Math.sign()
  • Math.sin()
  • Math.sinh()
  • Math.sqrt()
  • Math.tan()
  • Math.tanh()
  • Math.trunc()

@n14little
Copy link
Contributor

There are a couple of these functions that are not yet implemented. Are there separate issues tracking the implementation of those functions?

@HalidOdat
Copy link
Member Author

HalidOdat commented Jun 24, 2020

There are a couple of these functions that are not yet implemented. Are there separate issues tracking the implementation of those functions?

we don't have an issue for tracking the unimplemented ones. I'll create it :)

Edit: #524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics E-Easy Easy good first issue Good for newcomers technical debt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants