Source file: /~heha/ewa/Reluktanzmotor/cdesk-201007.zip/compat.h

#pragma once
//#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#include <windows.h>

const double PI		=3.1415926535897932384626433832795;
const double LN10	=2.30258509299404568402;
const double LOG2E	=1.44269504088896340736;
const double PI180	=PI/180;

#ifdef _M_IX86

#if _MSC_VER < 1900
#define __field_ecount_opt(x)
#define __out_ecount(x)
#define __out_bcount(x)

__forceinline __int64 llrint(double f) {
 __int64 i;
 _asm	fld	f
 _asm	fistp	i
 return i;
}
#endif

#if _MSC_VER < 1400	// Visual C++ 6
#pragma warning(disable:4035)
__forceinline char _BitScanForward(DWORD*Index, DWORD v) {
 _asm	bsf	eax,v
 _asm	mov	ecx,Index	// ohne ECX einzusauen geht es hier nicht
 _asm	mov	[ecx],eax
 _asm	setnz	al
}
__forceinline char _BitScanReverse(DWORD*Index, DWORD v) {
 _asm	bsr	eax,v
 _asm	mov	ecx,Index
 _asm	mov	[ecx],eax
 _asm	setnz	al
}
__forceinline char _bittest(const void*p, DWORD bitnum) {
 _asm	mov	ecx,p
 _asm	mov	eax,bitnum
 _asm	bt	dword ptr [ecx],eax
 _asm	setc	al
}
__forceinline char _bittestandset(void*p, DWORD bitnum) {
 _asm	mov	ecx,p
 _asm	mov	eax,bitnum
 _asm	bts	dword ptr [ecx],eax
 _asm	setc	al
}
__forceinline char _bittestandclear(void*p, DWORD bitnum) {
 _asm	mov	ecx,p
 _asm	mov	eax,bitnum
 _asm	btr	dword ptr [ecx],eax
 _asm	setc	al
}
__forceinline char _bittestandcomplement(void*p, DWORD bitnum) {
 _asm	mov	ecx,p
 _asm	mov	eax,bitnum
 _asm	btc	dword ptr [ecx],eax
 _asm	setc	al
}
__forceinline void __stosb(BYTE*p, BYTE val, DWORD count) {
 _asm	mov	edi,p
 _asm	mov	al,val
 _asm	mov	ecx,count
 _asm	rep stosb
}
__forceinline void __stosw(WORD*p, WORD val, DWORD count) {
 _asm	mov	edi,p
 _asm	mov	ax,val
 _asm	mov	ecx,count
 _asm	rep stosw
}
__forceinline void __stosd(DWORD*p, DWORD val, DWORD count) {
 _asm	mov	edi,p
 _asm	mov	eax,val
 _asm	mov	ecx,count
 _asm	rep stosd
}
__forceinline void __movsb(BYTE*d, const BYTE*s, DWORD count) {
 _asm	mov	edi,d
 _asm	mov	esi,s
 _asm	mov	ecx,count
 _asm	rep movsb
}
__forceinline void __movsw(WORD*d, const WORD*s, DWORD count) {
 _asm	mov	edi,d
 _asm	mov	esi,s
 _asm	mov	ecx,count
 _asm	rep movsw
}
__forceinline void __movsd(DWORD*d, const DWORD*s, DWORD count) {
 _asm	mov	edi,d
 _asm	mov	esi,s
 _asm	mov	ecx,count
 _asm	rep movsd
}
#pragma warning(default:4035)
#else
# include <intrin.h>
#endif
#else 
# include <intrin.h>
#endif

#if _MSC_VER < 1900	// lrint(), llrint() bei Visual C++ 2019 bereits definiert
# ifdef _M_IX86
inline int lrint(double x) {return (int)llrint(x);}
# else
inline __int64 llrint(double x) {return _mm_cvtsd_si64(*(__m128d*)&x);}
inline int lrint(double x) {return _mm_cvtsd_si32(*(__m128d*)&x);}
# endif
#endif

#ifndef GetWindowLongPtr
#  define GetWindowLongPtr GetWindowLong
#  define SetWindowLongPtr SetWindowLong
#  define ULONG_PTR DWORD
#endif
#define elemof(x) (sizeof(x)/sizeof((x)[0]))

//namespace std{
//}

//#ifdef _DEBUG
//# define assert(x) if (!(x)) DebugOut("%s(%d): Assert failed: %s\n",__FILE__,__LINE__,##x)
//#else
//# define assert(x)
//#endif

namespace my{
inline BOOL isfinite(float f) {return ~*((DWORD*)&f)&0x7F800000L;}


template<class T,int MAX> class fixvec{
  unsigned fill;
  T space[MAX];
public:
  fixvec(unsigned f=0):fill(f) {}
  typedef unsigned iterator;
  typedef T& reference;
  iterator begin() {return 0;}
  iterator end() {return fill;}
  iterator insert(iterator at,const T&val) {if (fill==MAX || at>=fill) return end(); memmove(space+at+1,space+at,fill-at-1); return at;}
  iterator erase(iterator at) {if (at>=fill) return end(); memmove(space+at,space+at+1,fill-at-1); return at;}
  reference operator[](unsigned i) {return space[i];}
  reference at(unsigned i) {return space[i>=fill ? fill:i];}
};
}
Detected encoding: ASCII (7 bit)2