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

[Merged by Bors] - Fix string.prototype methods and add static string methods #1123

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions boa/src/builtins/number/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ pub(crate) fn f64_to_int32(number: f64) -> i32 {
pub(crate) fn f64_to_uint32(number: f64) -> u32 {
f64_to_int32(number) as u32
}

/// Converts a 64-bit floating point number to an `u16` according to the [`ToUint16`][ToUint16] algorithm.
///
/// [ToUint16]: https://tc39.es/ecma262/#sec-touint16
#[inline]
pub(crate) fn f64_to_uint16(number: f64) -> u16 {
let n = f64_to_int32(number) as u32;
(n % (1 << 16)) as u16
}
2 changes: 1 addition & 1 deletion boa/src/builtins/number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use num_traits::{float::FloatCore, Num};

mod conversions;

pub(crate) use conversions::{f64_to_int32, f64_to_uint32};
pub(crate) use conversions::{f64_to_int32, f64_to_uint16, f64_to_uint32};

#[cfg(test)]
mod tests;
Expand Down
Loading