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 Math.signbit #333

Merged
merged 5 commits into from
Nov 18, 2018
Merged

add Math.signbit #333

merged 5 commits into from
Nov 18, 2018

Conversation

MaxGraey
Copy link
Member

No description provided.

@MaxGraey MaxGraey requested a review from dcodeIO November 17, 2018 11:40
std/assembly/math.ts Outdated Show resolved Hide resolved
@@ -2046,6 +2053,11 @@ export namespace NativeMathf {
}
}

@inline
export function signbit(x: f32): bool {
return <bool>((reinterpret<u32>(x) >>> 31) & <i32>(x == x));
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it might result in an unnecessary & 1 to convert from i32 to bool. A better way to write it is: <bool>(reinterpret<u32>(x) >>> 31) & (x == x), as it keeps type conversions to a minimum.

export function signbit(x: f64): bool {
// In ECMAScript all NaN values are indistinguishable from each other
// so we need handle NaN and negative NaN in similar way
return <bool>(<i32>(reinterpret<u64>(x) >>> 63 != 0) & <i32>(x == x));
Copy link
Member

Choose a reason for hiding this comment

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

Similar to the f32 version, the != 0 instruction can be saved here as well.

Copy link
Member Author

@MaxGraey MaxGraey Nov 17, 2018

Choose a reason for hiding this comment

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

I'm not sure. Because without != 0 u64 will be cast (extend op code) to i32 anyway

Copy link
Member

Choose a reason for hiding this comment

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

Oh, actually != 0 doesn't matter because it has to convert from 64 to 32 bits anyway.

@dcodeIO dcodeIO merged commit 4944280 into AssemblyScript:master Nov 18, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Nov 18, 2018

Thank you!

@MaxGraey MaxGraey deleted the Math#signbit branch November 18, 2018 11:10
willemneal pushed a commit to willemneal/assemblyscript that referenced this pull request Dec 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants