Re: ieee754 -0.0f?

Ash Henstock <[email protected]> Wed, 1 Feb 2006 20:18:22 +0000
Newsgroups gmane.games.devel.general
Message-ID <[email protected]>
Peter's earlier message with the union reminded me of some old, (horribly
non portable) code I had lying around. Marginally useful for fiddling with
float values, but mostly just a peculiarity. Scary :)

union __float
{
    struct
    {
        unsigned m_mantissa : 24;
        unsigned m_exponent : 7;
        unsigned m_sign : 1;
    };

    int m_int;
    unsigned int m_uint;
    float m_float;

    // -- a few implicit conversions
    __float(float _f) { m_float = _f; }
    __float(int _i) { m_int = _i; }
    __float(unsigned int _i) { m_uint = _i; }
};

#ifdef _DEBUG
#define float __float
#endif

int _tmain(int argc, _TCHAR* argv[])
{
    float f = 0;

    /* -- can set in VC debugger; the one I have here you can at least
    f.m_sign = 1;
    f.m_exponent = 0;
    f.m_mantissa = 0;
    */

    void* p = *(reinterpret_cast<void**>(&f));
    ::printf("%.16e = %p\n", f.m_float, p);

    return 0;
};

-- Ash.

On 2/1/06, Andras Balogh <[email protected]> wrote:
>
> > Notice in my previous post that I did "float b = 0.0f/-1.0f" ?
>
> Yep, I did, and already answered that, it's just that the turnaround of
> this mailing list is somewhat slow, so we are always one post behind :)
>
>
>
> andras
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Gamedevlists-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gamedevlists-general
> Archives:
> http://sourceforge.net/mailarchive/forum.php?forum_id=557
>