📄 extended.h
字号:
// Extended.h: interface for the Extended class.
// HouSisong@263.net 2003.3
//
// 扩展精度浮点数支持 Extended (范围+-3.6E-4951 .. +-1.1E4932 19-20位十进制精度)
// 它和long double,double,float,__int64,int等类型运算、赋值等兼容(仅内存格式不一样);
// (这种类型是x86 CPU浮点运算单元运算时使用的浮点类型,
// 它与Delphi中的内置浮点类型Extended类型完全一样)
// 由于CPU浮点部件支持这种类型,所以运算时不需要做什么特殊处理,速度上没有问题
//
// 封装它的原因: 我没有在VC中找到这种数据类型,但我又需要它
// MSDN: The "long double" data type (80-bit, 10-byte precision)
// is mapped directly to "double" (64-bit, 8- byte precision)
// in Windows NT and Windows 95
//////////////////////////////////////////////////////////////////////
#if !defined(HSS_EXTENDED_H__1ECD8DAE_80C2_4D79_9E0D_F80C031B8CA1__INCLUDED_)
#define HSS_EXTENDED_H__1ECD8DAE_80C2_4D79_9E0D_F80C031B8CA1__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//////////////////////////////////////////////////////
// 扩展精度浮点数Extended //
//////////////////////////////////////////////////////
class Extended //80位精度 浮点数
{
#define _ExFloatPtr tbyte Ptr
BYTE m_ValueSpace[10];//占80位,即10字节
public:
Extended () { } //为了效率,这里并没有赋予初始值0
Extended (const long double xf)
{ __asm { push eax
mov eax,this
fld xf
fstp _ExFloatPtr [eax]
pop eax } }
Extended (const double xf)
{ __asm { push eax
mov eax,this
fld xf
fstp _ExFloatPtr [eax]
pop eax } }
Extended (const float xf)
{ __asm { push eax
mov eax,this
fld xf
fstp _ExFloatPtr [eax]
pop eax } }
Extended (const __int64 xi)
{ __asm { push eax
mov eax,this
fild QWORD Ptr xi
fstp _ExFloatPtr [eax]
pop eax } }
Extended (const int xi)
{ __asm { push eax
mov eax,this
fild xi
fstp _ExFloatPtr [eax]
pop eax} }
Extended (const Extended &x) { *this=x; }
operator long double () const
{ long double d; __asm { push eax
mov eax,this
fld _ExFloatPtr [eax]
fstp d
pop eax}
return d; }
operator double () const
{ double d; __asm { push eax
mov eax,this
fld _ExFloatPtr [eax]
fstp d
pop eax}
return d; }
operator float () const
{ float d; __asm { push eax
mov eax,this
fld _ExFloatPtr [eax]
fstp d
pop eax }
return d; }
operator __int64 () const
{ __int64 d; __asm { push eax
mov eax,this
fld _ExFloatPtr [eax]
fistp QWord ptr d
pop eax}
return d; }
operator int () const
{ int d; __asm { push eax
mov eax,this
fld _ExFloatPtr [eax]
fistp d
pop eax}
return d; }
Extended& operator =(const long double xf)
{ __asm { push eax
mov eax,this
fld xf
fstp _ExFloatPtr [eax]
pop eax}
return *this; }
Extended& operator =(const double xf)
{ __asm { push eax
mov eax,this
fld xf
fstp _ExFloatPtr [eax]
pop eax}
return *this; }
Extended& operator =(const float xf)
{ __asm { push eax
mov eax,this
fld xf
fstp _ExFloatPtr [eax]
pop eax}
return *this; }
Extended& operator =(const __int64 xi)
{ __asm { push eax
mov eax,this
fild QWORD Ptr xi
fstp _ExFloatPtr [eax]
pop eax}
return *this; }
Extended& operator =(const int xi)
{ __asm { push eax
mov eax,this
fild xi
fstp _ExFloatPtr [eax]
pop eax }
return *this; }
Extended& operator+=(const Extended &x) { __asm{ push eax
mov eax,[x]
fld _ExFloatPtr [eax]
mov eax,this
fld _ExFloatPtr [eax]
faddp st(1),st
fstp _ExFloatPtr [eax]
pop eax }
return *this; }
Extended& operator-=(const Extended &x) { __asm{ push eax
mov eax,[x]
fld _ExFloatPtr [eax]
mov eax,this
fld _ExFloatPtr [eax]
fsubrp st(1),st
fstp _ExFloatPtr [eax]
pop eax }
return *this; }
Extended& operator*=(const Extended &x) { __asm{ push eax
mov eax,[x]
fld _ExFloatPtr [eax]
mov eax,this
fld _ExFloatPtr [eax]
fmulp st(1),st
fstp _ExFloatPtr [eax]
pop eax }
return *this; }
Extended& operator/=(const Extended &x) { __asm{ push eax
mov eax,[x]
fld _ExFloatPtr [eax]
mov eax,this
fld _ExFloatPtr [eax]
fdivrp st(1),st
fstp _ExFloatPtr [eax]
pop eax }
return *this; }
Extended& operator+=(const double xf) { __asm{ push eax
fld xf
mov eax,this
fld _ExFloatPtr [eax]
faddp st(1),st
fstp _ExFloatPtr [eax]
pop eax }
return *this; }
Extended& operator-=(const double xf) { __asm{ push eax
fld xf
mov eax,this
fld _ExFloatPtr [eax]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -