Ptex

PtexHalf.cpp
Go to the documentation of this file.
1 /*
2 PTEX SOFTWARE
3 Copyright 2014 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 <cmath>
37 #include "PtexHalf.h"
38
39 PTEX_NAMESPACE_BEGIN
40
41 #include "PtexHalfTables.h"
42
44 uint16_t PtexHalf::fromFloat_except(uint32_t i)
45 {
46 uint32_t s = ((i>>16) & 0x8000);
47 int32_t e = ((i>>13) & 0x3fc00) - 0x1c000;
48
49 if (e <= 0) {
50 // denormalized
51 union { uint32_t i; float f; } u;
52 u.i = i;
53 return (uint16_t)(s|int(fabs(u.f)*1.6777216e7 + .5));
54 }
55
56 if (e == 0x23c00)
57 // inf/nan, preserve msb bits of m for nan code
58 return (uint16_t)(s|0x7c00|((i&0x7fffff)>>13));
59 else
60 // overflow - convert to inf
61 return (uint16_t)(s|0x7c00);
62 }
63
64 PTEX_NAMESPACE_END
PtexHalfTables.h
PtexHalf::fromFloat_except
static uint16_t fromFloat_except(uint32_t val)
Handle exceptional cases for half-to-float conversion.
Definition: PtexHalf.cpp:44
PtexHalf.h
Half-precision floating-point type.
PTEX_NAMESPACE_BEGIN
Definition: PtexSeparableKernel.cpp:42
PTEX_NAMESPACE_END
#define PTEX_NAMESPACE_END
Definition: PtexVersion.h:62