Blame IlmImfTest/compareFloat.cpp

Packit Service 6754ca
//////////////////////////////////////////////////////////////////////////////
Packit Service 6754ca
//
Packit Service 6754ca
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucasfilm
Packit Service 6754ca
// Entertainment Company Ltd.  Portions contributed and copyright held by
Packit Service 6754ca
// others as indicated.  All rights reserved.
Packit Service 6754ca
//
Packit Service 6754ca
// Redistribution and use in source and binary forms, with or without
Packit Service 6754ca
// modification, are permitted provided that the following conditions are
Packit Service 6754ca
// met:
Packit Service 6754ca
//
Packit Service 6754ca
//     * Redistributions of source code must retain the above
Packit Service 6754ca
//       copyright notice, this list of conditions and the following
Packit Service 6754ca
//       disclaimer.
Packit Service 6754ca
//
Packit Service 6754ca
//     * Redistributions in binary form must reproduce the above
Packit Service 6754ca
//       copyright notice, this list of conditions and the following
Packit Service 6754ca
//       disclaimer in the documentation and/or other materials provided with
Packit Service 6754ca
//       the distribution.
Packit Service 6754ca
//
Packit Service 6754ca
//     * Neither the name of Industrial Light & Magic nor the names of
Packit Service 6754ca
//       any other contributors to this software may be used to endorse or
Packit Service 6754ca
//       promote products derived from this software without specific prior
Packit Service 6754ca
//       written permission.
Packit Service 6754ca
//
Packit Service 6754ca
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
Packit Service 6754ca
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
Packit Service 6754ca
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
Packit Service 6754ca
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
Packit Service 6754ca
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit Service 6754ca
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit Service 6754ca
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit Service 6754ca
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit Service 6754ca
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit Service 6754ca
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit Service 6754ca
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 6754ca
//
Packit Service 6754ca
//////////////////////////////////////////////////////////////////////////////
Packit Service 6754ca
Packit Service 6754ca
#include "compareFloat.h"
Packit Service 6754ca
Packit Service 6754ca
using namespace OPENEXR_IMF_NAMESPACE;
Packit Service 6754ca
Packit Service 6754ca
bool
Packit Service 6754ca
equivalent (float f1, float f2, Compression comp)
Packit Service 6754ca
{
Packit Service 6754ca
    //
Packit Service 6754ca
    // Test if a float, f1, is "equivalent" to another float, f2,
Packit Service 6754ca
    // which results from storing f1 in an image file, and reading
Packit Service 6754ca
    // it back:
Packit Service 6754ca
    // If the file was compressed with PXR24_COMPRESSION, then f1
Packit Service 6754ca
    // and f2 must the same as f1 rounded to 24 bits (see class
Packit Service 6754ca
    // ImfPxr24Compressor); otherwise f1 and f2 must be the same.
Packit Service 6754ca
    //
Packit Service 6754ca
Packit Service 6754ca
    union
Packit Service 6754ca
    {
Packit Service 6754ca
	float		f;
Packit Service 6754ca
	unsigned int	i;
Packit Service 6754ca
    } u1, u2;
Packit Service 6754ca
Packit Service 6754ca
    u1.f = f1;
Packit Service 6754ca
    u2.f = f2;
Packit Service 6754ca
Packit Service 6754ca
    if (comp == PXR24_COMPRESSION)
Packit Service 6754ca
	return (u2.i >> 8) - (u1.i >> 8) < 2;
Packit Service 6754ca
    else
Packit Service 6754ca
	return u2.i == u1.i;
Packit Service 6754ca
}