52 #ifndef __vtkFastNumericConversion_h
53 #define __vtkFastNumericConversion_h
55 #include "vtkCommonMathModule.h"
60 #if defined(NDEBUG) && (defined i386 || defined _M_IX86)
71 #if defined(__linux__)
76 #ifdef VTK_TEST_HACK_TO_EMULATE_LINUX_UNDER_WINDOWS
106 return ConvertFixedPoint(val, frac);
112 ConvertFixedPoint(val, frac);
131 return static_cast<double>(
static_cast<unsigned long>(1) << 30);
140 return (static_cast<unsigned long>(1) << (52-30)) * two30();
152 return (static_cast<unsigned long>(1) << (51-30)) * two30();
162 return (static_cast<unsigned long>(1) << (63-60)) * two30() * two30();
172 return (static_cast<unsigned long>(1) << (62-60)) * two30() * two30();
222 static inline double RoundingTieBreaker()
224 return 1.0 / (two30() * (
static_cast<unsigned long>(1) << (
EXT_BITS -
INT_BITS - 30)));
242 {
return two52() * BorrowBit(); };
252 {
return two51() * BorrowBit(); };
260 {
return two63() * BorrowBit(); };
268 {
return two62() * BorrowBit(); };
276 #ifdef VTK_WORDS_BIGENDIAN
277 enum {exponent_pos = 0, mantissa_pos = 1};
279 enum {exponent_pos = 1, mantissa_pos = 0};
303 unsigned long mtime = this->
GetMTime();
304 this->SetinternalReservedFracBits(bits);
307 this->InternalRebuild();
330 static int QuickFloor(
const double &val);
346 static int SafeFloor(
const double &val);
357 static int Round(
const double &val);
365 union {
int i[2];
double d; } u;
367 u.d = (((val - fixRound)
368 + this->epTempDenormalizer)
369 - this->epTempDenormalizer)
370 + this->fpDenormalizer;
371 #else // ! VTK_EXT_PREC
372 u.d = (val - fixRound)
373 + this->fpDenormalizer;
374 #endif // VTK_EXT_PREC
375 fracPart = (u.i[mantissa_pos] & fracMask) >> 1;
376 return u.i[mantissa_pos] >> this->internalReservedFracBits;
386 void InternalRebuild(
void);
389 vtkSetMacro(internalReservedFracBits,
int);
390 vtkGetMacro(internalReservedFracBits,
int);
392 #ifndef VTK_LEGACY_SILENT
393 static int QuickFloorInline(
const double &val);
394 static int SafeFloorInline(
const double &val);
395 static int RoundInline(
const double &val);
398 int internalReservedFracBits;
404 double fpDenormalizer;
407 double epTempDenormalizer;
418 #ifndef VTK_LEGACY_SILENT
419 inline int vtkFastNumericConversion::QuickFloorInline(
const double &val)
425 union {
int i[2];
double d; } u;
427 u.d = (((val - (QuickRoundAdjust() - RoundingTieBreaker()))
429 + QuickExtPrecTempDenormalizer())
431 - QuickExtPrecTempDenormalizer())
432 + QuickFloorDenormalizer();
433 #else // ! VTK_EXT_PREC
434 u.d = (val - (QuickRoundAdjust() - RoundingTieBreaker()))
435 + QuickFloorDenormalizer();
436 #endif // VTK_EXT_PREC
437 return u.i[mantissa_pos];
438 #else // ! VTK_USE_TRICK
439 return static_cast<int>(val);
440 #endif // VTK_USE_TRICK
443 #ifndef VTK_LEGACY_SILENT
444 inline int vtkFastNumericConversion::SafeFloorInline(
const double &val)
450 union {
int i[2];
double d; } u;
452 u.d = (((val - SafeRoundAdjust())
453 + SafeExtPrecTempDenormalizer())
454 - SafeExtPrecTempDenormalizer())
455 + SafeFloorDenormalizer();
456 #else // ! VTK_EXT_PREC
457 u.d = (val - SafeRoundAdjust())
458 + SafeFloorDenormalizer();
459 #endif // VTK_EXT_PREC
460 return u.i[mantissa_pos] >> SafeFinalShift();
461 #else // ! VTK_USE_TRICK
462 return static_cast<int>(val);
463 #endif // VTK_USE_TRICK
466 #ifndef VTK_LEGACY_SILENT
467 inline int vtkFastNumericConversion::RoundInline(
const double &val)
473 union {
int i[2];
double d; } u;
476 + QuickExtPrecTempDenormalizer())
477 - QuickExtPrecTempDenormalizer())
478 + QuickFloorDenormalizer();
479 #else // ! VTK_EXT_PREC
481 + QuickFloorDenormalizer();
482 #endif // VTK_EXT_PREC
483 return u.i[mantissa_pos];
484 #else // ! VTK_USE_TRICK
487 return static_cast<int>(val + 0.5);
491 return static_cast<int>(val - 0.5);
493 #endif // VTK_USE_TRICK
static double QuickRoundAdjust()
static double SafeExtPrecTempDenormalizer()
static int QuickFloor(const double &val)
int TestConvertFixedPointFracPart(double val)
abstract base class for most VTK objects
int TestSafeFloor(double val)
static int SafeFinalShift()
static double BorrowBit()
static double SafeFloorDenormalizer()
int TestConvertFixedPointIntPart(double val)
static double RoundingTieBreaker()
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual unsigned long GetMTime()
a simple class to control print indentation
Enables fast conversion of floating point to fixed point.
int TestQuickFloor(double val)
static int SafeFloor(const double &val)
void SetReservedFracBits(int bits)
static double QuickFloorDenormalizer()
int ConvertFixedPoint(const double &val, int &fracPart)
static double QuickExtPrecTempDenormalizer()
static double SafeRoundAdjust()
~vtkFastNumericConversion()
static int Round(const double &val)
int TestRound(double val)