ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/frexp.c
Revision: 1.2
Committed: Sat Feb 22 02:07:22 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +57 -2 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /* ====================================================================
5 * The Radiance Software License, Version 1.0
6 *
7 * Copyright (c) 1990 - 2002 The Regents of the University of California,
8 * through Lawrence Berkeley National Laboratory. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. The end-user documentation included with the redistribution,
23 * if any, must include the following acknowledgment:
24 * "This product includes Radiance software
25 * (http://radsite.lbl.gov/)
26 * developed by the Lawrence Berkeley National Laboratory
27 * (http://www.lbl.gov/)."
28 * Alternately, this acknowledgment may appear in the software itself,
29 * if and wherever such third-party acknowledgments normally appear.
30 *
31 * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
32 * and "The Regents of the University of California" must
33 * not be used to endorse or promote products derived from this
34 * software without prior written permission. For written
35 * permission, please contact [email protected].
36 *
37 * 5. Products derived from this software may not be called "Radiance",
38 * nor may "Radiance" appear in their name, without prior written
39 * permission of Lawrence Berkeley National Laboratory.
40 *
41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This software consists of voluntary contributions made by many
56 * individuals on behalf of Lawrence Berkeley National Laboratory. For more
57 * information on Lawrence Berkeley National Laboratory, please see
58 * <http://www.lbl.gov/>.
59 */
60
61 frexp(x, ip) /* call it paranoia, I've seen the lib version */
62 register double x;
63 int *ip;
64 {
65 int neg;
66 register int i;
67
68 if (neg = (x < 0.0))
69 x = -x;
70 else if (x == 0.0) {
71 *ip = 0;
72 return(0.0);
73 }
74 if (x < 0.5)
75 for (i = 0; x < 0.5; i--)
76 x *= 2.0;
77 else
78 for (i = 0; x >= 1.0; i++)
79 x /= 2.0;
80 *ip = i;
81 if (neg)
82 return(-x);
83 else
84 return(x);
85 }