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