The Nebula Device 3: Debug::DebugFloat Class Reference

The Nebula Device 3

Debug::DebugFloat Class Reference

#include <debugfloat.h>


Detailed Description

This class is supposed to make it easier, to restore the exact value of floating- point-based types, like vector, matrix44, float etc. for debugging. printf cuts values and rounds it. Also denormalized values might be printed as "0.0". Its particulary useful, if a certain set of input-parameters lets a function crash. Just call printHex for floating-point-based params so they are being printed to stdout with its exact bit-pattern. That dump can be passed to restoreHex and you can debug that function with that particular input-set.

Printing a float4 to stdout works like this:

float4 v(1.0f, 2.0f, 3.0f, 4.0f); DebugFloat::printHex(v, "v");

The output in stdout is this:

v: 0x3F800000, 0x40000000, 0x40400000, 0x40800000

To restore the values, just pass the output to restoreHex

float4 v = DebugFloat::restoreHex(0x3F800000, 0x40000000, 0x40400000, 0x40800000);

Now v has the exact same value(bit pattern) as it had when being printed with printHex

There is also a normal "print" for each type. Quite useful is the quaternion-version, since it gives a more human-readable output than just the normal debugger.

(C) 2009 Radon Labs GmbH

Static Public Member Functions

static void printHex (float val, const char *msg=NULL)
 print float's bit pattern as hex to stdout
static void printHex (const Math::float4 &v, const char *msg=NULL)
 print float4's bit pattern as hex to stdout
static void printHex (const Math::matrix44 &m, const char *msg=NULL)
 print matrix's bit pattern as hex to stdout
static void printHex (const Math::quaternion &q, const char *msg=NULL)
 print quaternion's bit pattern as hex to stdout
static void printHex (const Math::plane &p, const char *msg=NULL)
 print plane's bit pattern as hex to stdout
static void print (const float &v, const char *msg=NULL)
 print float's values plain to stdout
static void print (const Math::float4 &v, const char *msg=NULL)
 print float4's values plain to stdout
static void print (const Math::matrix44 &m, const char *msg=NULL)
 print matrix's values plain to stdout
static void print (const Math::quaternion &q, const char *msg=NULL)
 print quaternion's values plain to stdout
static void print (const Math::plane &p, const char *msg=NULL)
 print plane's values plain to stdout