The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | |
| 2 | /* @(#)e_scalb.c 1.3 95/01/18 */ |
| 3 | /* |
| 4 | * ==================================================== |
| 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 6 | * |
| 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. |
| 8 | * Permission to use, copy, modify, and distribute this |
| 9 | * software is freely granted, provided that this notice |
| 10 | * is preserved. |
| 11 | * ==================================================== |
| 12 | */ |
| 13 | |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 14 | #include <sys/cdefs.h> |
| 15 | __FBSDID("$FreeBSD$"); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 16 | |
| 17 | /* |
Elliott Hughes | 4088e3a | 2023-08-03 13:33:56 -0700 | [diff] [blame^] | 18 | * scalb(x, fn) is provide for |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 19 | * passing various standard test suite. One |
| 20 | * should use scalbn() instead. |
| 21 | */ |
| 22 | |
| 23 | #include "math.h" |
| 24 | #include "math_private.h" |
| 25 | |
| 26 | #ifdef _SCALB_INT |
| 27 | double |
Elliott Hughes | 4088e3a | 2023-08-03 13:33:56 -0700 | [diff] [blame^] | 28 | scalb(double x, int fn) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #else |
| 30 | double |
Elliott Hughes | 4088e3a | 2023-08-03 13:33:56 -0700 | [diff] [blame^] | 31 | scalb(double x, double fn) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 32 | #endif |
| 33 | { |
| 34 | #ifdef _SCALB_INT |
| 35 | return scalbn(x,fn); |
| 36 | #else |
| 37 | if (isnan(x)||isnan(fn)) return x*fn; |
| 38 | if (!finite(fn)) { |
| 39 | if(fn>0.0) return x*fn; |
| 40 | else return x/(-fn); |
| 41 | } |
| 42 | if (rint(fn)!=fn) return (fn-fn)/(fn-fn); |
| 43 | if ( fn > 65000.0) return scalbn(x, 65000); |
| 44 | if (-fn > 65000.0) return scalbn(x,-65000); |
| 45 | return scalbn(x,(int)fn); |
| 46 | #endif |
| 47 | } |