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

copysign #4752

Closed
vicuna opened this issue Mar 19, 2009 · 7 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Mar 19, 2009

Original bug ID: 4752
Reporter: @Chris00
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2012-09-25T18:06:17Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.11.0
Fixed in version: 3.13.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @glondu @hcarty @dbuenzli @Chris00

Bug description

A fast function [copysign : float -> float -> float] would be nice (working for all float values, including [nan]). It is more or less possible to write one with the standard library functions but it is not fast enough.

@vicuna

This comment has been minimized.

Copy link
Author

commented Apr 3, 2011

Comment author: @Chris00

Note that it is also in the microsoft visual studio library under the name _copysign.
http://msdn.microsoft.com/en-us/library/aa246720.aspx

@vicuna

This comment has been minimized.

Copy link
Author

commented May 29, 2011

Comment author: @xavierleroy

How fast is "fast" ? If a call to a C function is fast enough, I see no problem implementing this function, either as a call to "copysign" if available, or through bit-twiddling in C. If inline assembly is expected, that's a lot more work...

@vicuna

This comment has been minimized.

Copy link
Author

commented May 29, 2011

Comment author: @Chris00

A C function is good. If it is not fast enough we can always bother you for the second solution later. ;)

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 4, 2011

Comment author: @xavierleroy

Implemented in SVN trunk (as a C function). Will go in release 3.13.0.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 7, 2011

Comment author: @xavierleroy

A question occurs to me re: behavior w.r.t. NaN. The current implementation, like C99's copysign() function, has:
copysign nan y = nan
copysign x nan = x or -x depending on the sign bit of the nan.
I wonder whether "copysign x nan = nan" would make more sense. At least that would make the copysign function fully specified. Any opinions in favor or against?

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 7, 2011

Comment author: @Chris00

IMHO, it is good to leave copysign as a way of extracting the sign of a nan.¹ (That behavior does not mean to me that is it not completely specified.) It is sometimes used; see for example ftp://ftp.win.ua.ac.be/pub/preprints/03/criticism.pdf p.2.

¹ Despite the fact that there are surprises: copysign 1. ((±0.) /. (±0.)) = -1.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 9, 2011

Comment author: @xavierleroy

All right, I'll leave copysign's behavior as it is today. Thanks for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.