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 #16592

Merged
merged 4 commits into from
Jan 7, 2021
Merged

add math.signbit #16592

merged 4 commits into from
Jan 7, 2021

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Jan 5, 2021

C99 function

Ref timotheecour#505

@ringabout ringabout changed the title add signbit add math.signbit Jan 5, 2021
tests/stdlib/tmath.nim Outdated Show resolved Hide resolved
tests/stdlib/tmath.nim Outdated Show resolved Hide resolved
@Araq
Copy link
Member

Araq commented Jan 6, 2021

We target C89 though. Also, why do we need it? One can always cast to uint64 and check the sign bit.

@timotheecour
Copy link
Member

We target C89 though

plenty of code in stdlib use functions that require >= C99, see https://en.wikibooks.org/wiki/C_Programming/math.h, so there's no reason to single this one out; future work can improve general support for C89 (via when not defined(nimc99) maybe) but this shouldn't be at the expense of performance for the vast majority of use cases that can assume >= C99.

One can always cast to uint64 and check the sign bit.

that wouldn't be portable, it'd depend on the FP type, endian-ness, architecture; note that FP endian-ness is not simple, eg see https://en.wikipedia.org/wiki/Endianness

Although the ubiquitous x86 processors of today use little-endian storage for all types of data (integer, floating point), there are a number of hardware architectures where floating-point numbers are represented in big-endian form while integers are represented in little-endian form
here are ARM processors that have half little-endian, half big-endian floating-point representation for double-precision numbers: both 32-bit words are stored in little-endian like integer registers, but the most significant one first

etc...

@ringabout
Copy link
Member Author

ringabout commented Jan 7, 2021

It is useful for making copysign work robust in JS backend.
#16609

It is also useful for making nan consistent in CT and RT

timotheecour#499

@Araq Araq merged commit bab0aa6 into nim-lang:devel Jan 7, 2021
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
@ringabout ringabout mentioned this pull request Feb 7, 2024
1 task
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.

3 participants