1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS System Libraries
4 * FILE: win32ss/gdi/gdi32/objects/efloat.c
5 * PURPOSE: Functions to convert between FLOAT and EFLOAT
6 * PROGRAMMER: James Tabor
7 */
8 #include <precomp.h>
9
10 /* the following deal with IEEE single-precision numbers */
11 #define EXCESS 126L
12 #define SIGNBIT 0x80000000L
13 #define SIGN(fp) ((fp) & SIGNBIT)
14 #define EXP(fp) (((fp) >> 23L) & 0xFF)
15 #define MANT(fp) ((fp) & 0x7FFFFFL)
16 #define PACK(s,e,m) ((s) | ((e) << 23L) | (m))
17
18 FLOATL
19 FASTCALL
EFtoF(EFLOAT_S * efp)20 EFtoF(EFLOAT_S * efp)
21 {
22 ULONG Mant, Exp, Sign;
23
24 if (!efp->lMant) return 0;
25
26 Mant = efp->lMant;
27 Exp = efp->lExp;
28 Sign = SIGN(Mant);
29
30 if (Sign) Mant = -(LONG)Mant;
31 Mant >>= 7;
32 Exp += (EXCESS-1);
33
34 Mant = MANT(Mant);
35 return PACK(Sign, Exp, Mant);
36 }
37
38 VOID
39 FASTCALL
FtoEF(EFLOAT_S * efp,FLOATL f)40 FtoEF( EFLOAT_S * efp, FLOATL f)
41 {
42 ULONG Mant, Exp, Sign = 0;
43 gxf_long worker;
44
45 #ifdef _X86_
46 worker.l = f; // It's a float stored in a long.
47 #else
48 worker.f = f;
49 #endif
50
51 Exp = EXP(worker.l);
52 Mant = MANT(worker.l);
53 if (SIGN(worker.l)) Sign = -1;
54
55 Mant = ((Mant << 7) | 0x40000000);
56 Mant ^= Sign;
57 Mant -= Sign;
58 Exp -= (EXCESS-1);
59
60 efp->lMant = Mant;
61 efp->lExp = Exp;
62 }
63