1 /*
2  *  Mathlib : A C Library of Special Functions
3  *  Copyright (C) 1998 Ross Ihaka
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, a copy is available at
17  *  http://www.r-project.org/Licenses/
18  *
19  *  SYNOPSIS
20  *
21  *    #include <Rmath.h>
22  *    double fsign(double x, double y);
23  *
24  *  DESCRIPTION
25  *
26  *    This function performs transfer of sign.  The result is:
27  *
28  *                        |x| * signum(y)
29  */
30 
31 #include "nmath.h"
32 
fsign(double x,double y)33 double fsign(double x, double y)
34 {
35 #ifdef IEEE_754
36     if (ISNAN(x) || ISNAN(y))
37 	return x + y;
38 #endif
39     return ((y >= 0) ? fabs(x) : -fabs(x));
40 }
41