ScummVM API documentation
xpfloat.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef COMMON_XPFLOAT_H
23 #define COMMON_XPFLOAT_H
24 
25 // 80-bit extended precision floating point
26 // Mostly encountered stored as data on Apple systems
27 
28 #include "common/scummsys.h"
29 
30 namespace Common {
31 
32 struct XPFloat {
33  uint16 signAndExponent;
34  uint64 mantissa;
35 
36  enum Semantics {
37  kSemanticsMC68881,
38  kSemanticsSANE = kSemanticsMC68881,
39 
40  // Could add Intel 8087 and derivatives here since they're mostly compatible,
41  // but have different NaN/INF flag cases.
42  };
43 
44  XPFloat();
45  XPFloat(uint16 signAndExponent, uint64 mantissa);
46 
47  static XPFloat fromDouble(double value, Semantics semantics = kSemanticsMC68881);
48  static XPFloat fromDoubleBits(uint64 value, Semantics semantics = kSemanticsMC68881);
49 
50  void toDoubleSafe(double &result, bool &outOverflowed, Semantics semantics = kSemanticsMC68881) const;
51  void toDoubleBitsSafe(uint64 &result, bool &outOverflowed, Semantics semantics = kSemanticsMC68881) const;
52 
53  // Simple version that clamps to infinity and warns on overflow
54  double toDouble(Semantics semantics = kSemanticsMC68881) const;
55 };
56 
57 inline XPFloat::XPFloat() : signAndExponent(0), mantissa(0) {}
58 inline XPFloat::XPFloat(uint16 fSignAndExponent, uint64 fMantissa) : signAndExponent(fSignAndExponent), mantissa(fMantissa) {}
59 
60 }
61 
62 #endif
Definition: algorithm.h:29
Definition: xpfloat.h:32