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

add remaining math methods (#524) #525

Merged
merged 11 commits into from
Jul 2, 2020

Conversation

mr-rodgers
Copy link
Contributor

@mr-rodgers mr-rodgers commented Jun 24, 2020

This Pull Request fixes/closes #524.

It changes the following (work-in-progress):

  • Math.clz32()
  • Math.expm1()
  • Math.fround()
  • Math.hypot()
  • Math.log1p()
  • Math.imul()

@codecov
Copy link

codecov bot commented Jun 24, 2020

Codecov Report

Merging #525 into master will increase coverage by 0.35%.
The diff coverage is 94.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #525      +/-   ##
==========================================
+ Coverage   68.10%   68.46%   +0.35%     
==========================================
  Files         169      169              
  Lines        9942    10080     +138     
==========================================
+ Hits         6771     6901     +130     
- Misses       3171     3179       +8     
Impacted Files Coverage Δ
boa/src/builtins/math/mod.rs 75.89% <75.00%> (-0.18%) ⬇️
boa/src/builtins/math/tests.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b40e9e...e51ee81. Read the comment docs.

Comment on lines 180 to 184
.and_then(|x| f64::from(x).to_u32())
.map_or(32usize, |u| {
let s = format!("{:032b}", u);
s.chars().take_while(|x| *x == '0').count()
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.and_then(|x| f64::from(x).to_u32())
.map_or(32usize, |u| {
let s = format!("{:032b}", u);
s.chars().take_while(|x| *x == '0').count()
})
.and_then(|x| i32::from(x).leading_zeros())
.unwrap_or(32)

A better way of doing this would we to use .leading_zeros() which would eliminate the allocation from format!

@Razican Razican linked an issue Jun 25, 2020 that may be closed by this pull request
6 tasks
@Razican Razican added builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request labels Jun 25, 2020
@mr-rodgers mr-rodgers marked this pull request as ready for review June 25, 2020 21:31
@mr-rodgers mr-rodgers changed the title add Math.clz32 method (#524) add remaining math methods (#524) Jun 25, 2020
@pedropaulosuzuki pedropaulosuzuki mentioned this pull request Jun 26, 2020
Copy link
Contributor

@pedropaulosuzuki pedropaulosuzuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I'd write some more things on the tests, just to be sure. I know your implementation is correct, but maybe a new implementation in a future refactor might not be. Either way, looks pretty good to me.

boa/src/builtins/math/tests.rs Show resolved Hide resolved
boa/src/builtins/math/tests.rs Show resolved Hide resolved
boa/src/builtins/math/tests.rs Show resolved Hide resolved
boa/src/builtins/math/tests.rs Show resolved Hide resolved
@HalidOdat HalidOdat modified the milestones: v0.10.0, v0.9.0 Jun 26, 2020
Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect! The additional tests would be nice :)

Copy link
Contributor

@pedropaulosuzuki pedropaulosuzuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!!

@HalidOdat HalidOdat modified the milestones: v0.9.0, v0.10.0 Jul 2, 2020
@HalidOdat HalidOdat merged commit d9ef1fb into boa-dev:master Jul 2, 2020
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 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the rest of Math methods
4 participants