~ubuntu-branches/ubuntu/saucy/openexr/saucy

« back to all changes in this revision

Viewing changes to Imath/ImathFun.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adeodato Simó
  • Date: 2008-03-24 23:00:21 UTC
  • mfrom: (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080324230021-gnofz9mnvcj1xlv3
Tags: 1.6.1-3
Disable (hopefully temporarily) the test suite on arm and ia64.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
///////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
4
 
// Digital Ltd. LLC
5
 
// 
6
 
// All rights reserved.
7
 
// 
8
 
// Redistribution and use in source and binary forms, with or without
9
 
// modification, are permitted provided that the following conditions are
10
 
// met:
11
 
// *       Redistributions of source code must retain the above copyright
12
 
// notice, this list of conditions and the following disclaimer.
13
 
// *       Redistributions in binary form must reproduce the above
14
 
// copyright notice, this list of conditions and the following disclaimer
15
 
// in the documentation and/or other materials provided with the
16
 
// distribution.
17
 
// *       Neither the name of Industrial Light & Magic nor the names of
18
 
// its contributors may be used to endorse or promote products derived
19
 
// from this software without specific prior written permission. 
20
 
// 
21
 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
 
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
 
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
 
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
 
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
 
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
 
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
 
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
 
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
 
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 
//
33
 
///////////////////////////////////////////////////////////////////////////
34
 
 
35
 
 
36
 
#include <ImathFun.h>
37
 
#include <limits.h>
38
 
 
39
 
 
40
 
namespace Imath {
41
 
 
42
 
 
43
 
#if ULONG_MAX == 18446744073709551615LU
44
 
    typedef      long unsigned int Int64;
45
 
#else
46
 
    typedef long long unsigned int Int64;
47
 
#endif
48
 
 
49
 
 
50
 
float
51
 
succf (float f)
52
 
{
53
 
    union {float f; int i;} u;
54
 
    u.f = f;
55
 
 
56
 
    if ((u.i & 0x7f800000) == 0x7f800000)
57
 
    {
58
 
        // Nan or infinity; don't change value.
59
 
    }
60
 
    else if (u.i == 0x00000000 || u.i == 0x80000000)
61
 
    {
62
 
        // Plus or minus zero.
63
 
 
64
 
        u.i = 0x00000001;
65
 
    }
66
 
    else if (u.i > 0)
67
 
    {
68
 
        // Positive float, normalized or denormalized.
69
 
        // Incrementing the largest positive float
70
 
        // produces +infinity.
71
 
 
72
 
        ++u.i;
73
 
    }
74
 
    else
75
 
    {
76
 
        // Negative normalized or denormalized float.
77
 
 
78
 
        --u.i;
79
 
    }
80
 
 
81
 
    return u.f;
82
 
}
83
 
 
84
 
 
85
 
float
86
 
predf (float f)
87
 
{
88
 
    union {float f; int i;} u;
89
 
    u.f = f;
90
 
 
91
 
    if ((u.i & 0x7f800000) == 0x7f800000)
92
 
    {
93
 
        // Nan or infinity; don't change value.
94
 
    }
95
 
    else if (u.i == 0x00000000 || u.i == 0x80000000)
96
 
    {
97
 
        // Plus or minus zero.
98
 
 
99
 
        u.i = 0x80000001;
100
 
    }
101
 
    else if (u.i > 0)
102
 
    {
103
 
        // Positive float, normalized or denormalized.
104
 
 
105
 
        --u.i;
106
 
    }
107
 
    else
108
 
    {
109
 
        // Negative normalized or denormalized float.
110
 
        // Decrementing the largest negative float
111
 
        // produces -infinity.
112
 
 
113
 
        ++u.i;
114
 
    }
115
 
 
116
 
    return u.f;
117
 
}
118
 
 
119
 
 
120
 
double
121
 
succd (double d)
122
 
{
123
 
    union {double d; Int64 i;} u;
124
 
    u.d = d;
125
 
 
126
 
    if ((u.i & 0x7ff0000000000000LL) == 0x7ff0000000000000LL)
127
 
    {
128
 
        // Nan or infinity; don't change value.
129
 
    }
130
 
    else if (u.i == 0x0000000000000000LL || u.i == 0x8000000000000000LL)
131
 
    {
132
 
        // Plus or minus zero.
133
 
 
134
 
        u.i = 0x0000000000000001LL;
135
 
    }
136
 
    else if (u.i > 0)
137
 
    {
138
 
        // Positive double, normalized or denormalized.
139
 
        // Incrementing the largest positive double
140
 
        // produces +infinity.
141
 
 
142
 
        ++u.i;
143
 
    }
144
 
    else
145
 
    {
146
 
        // Negative normalized or denormalized double.
147
 
 
148
 
        --u.i;
149
 
    }
150
 
 
151
 
    return u.d;
152
 
}
153
 
 
154
 
 
155
 
double
156
 
predd (double d)
157
 
{
158
 
    union {double d; Int64 i;} u;
159
 
    u.d = d;
160
 
 
161
 
    if ((u.i & 0x7ff0000000000000LL) == 0x7ff0000000000000LL)
162
 
    {
163
 
        // Nan or infinity; don't change value.
164
 
    }
165
 
    else if (u.i == 0x0000000000000000LL || u.i == 0x8000000000000000LL)
166
 
    {
167
 
        // Plus or minus zero.
168
 
 
169
 
        u.i = 0x8000000000000001LL;
170
 
    }
171
 
    else if (u.i > 0)
172
 
    {
173
 
        // Positive double, normalized or denormalized.
174
 
 
175
 
        --u.i;
176
 
    }
177
 
    else
178
 
    {
179
 
        // Negative normalized or denormalized double.
180
 
        // Decrementing the largest negative double
181
 
        // produces -infinity.
182
 
 
183
 
        ++u.i;
184
 
    }
185
 
 
186
 
    return u.d;
187
 
}
188
 
 
189
 
 
190
 
} // namespace Imath