Ptex: PtexHalf.cpp Source File

Ptex

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

PtexHalf.cpp
Go to the documentation of this file.
1 /*
2 PTEX SOFTWARE
3 Copyright 2009 Disney Enterprises, Inc. All rights reserved
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17 * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
18 Studios" or the names of its contributors may NOT be used to
19 endorse or promote products derived from this software without
20 specific prior written permission from Walt Disney Pictures.
21
22 Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
25 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
26 IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
34 */
35
36 #include <math.h>
37 #include "PtexHalf.h"
38 #include "PtexHalfTables.h"
39
41 uint16_t PtexHalf::fromFloat_except(uint32_t i)
42 {
43 uint32_t s = ((i>>16) & 0x8000);
44 int32_t e = ((i>>13) & 0x3fc00) - 0x1c000;
45
46 if (e <= 0) {
47 // denormalized
48 union { uint32_t i; float f; } u;
49 u.i = i;
50 return (uint16_t)(s|int(fabs(u.f)*1.6777216e7 + .5));
51 }
52
53 if (e == 0x23c00)
54 // inf/nan, preserve msb bits of m for nan code
55 return (uint16_t)(s|0x7c00|((i&0x7fffff)>>13));
56 else
57 // overflow - convert to inf
58 return (uint16_t)(s|0x7c00);
59 }
PtexHalfTables.h
PtexHalf::fromFloat_except
static uint16_t fromFloat_except(uint32_t val)
Handle exceptional cases for half-to-float conversion.
Definition: PtexHalf.cpp:41
PtexHalf.h
Half-precision floating-point type.