Browse Source

core: start working on a "real" class for arbitrarily sized floats.

legacy
Sam Hocevar sam 13 years ago
parent
commit
5fc298964b
5 changed files with 93 additions and 1 deletions
  1. +1
    -0
      src/Makefile.am
  2. +1
    -0
      src/core.h
  3. +48
    -0
      src/real.cpp
  4. +42
    -0
      src/real.h
  5. +1
    -1
      test/Makefile.am

+ 1
- 0
src/Makefile.am View File

@@ -11,6 +11,7 @@ liblol_a_SOURCES = \
text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \
worldentity.cpp worldentity.h gradient.cpp gradient.h half.cpp half.h \
platform.cpp platform.h sprite.cpp sprite.h trig.cpp trig.h \
real.cpp real.h \
\
lol/unit.h \
\


+ 1
- 0
src/core.h View File

@@ -64,6 +64,7 @@ static inline int isnan(float f)
// Base types
#include "trig.h"
#include "half.h"
#include "real.h"
#include "matrix.h"
#include "numeric.h"
#include "timer.h"


+ 48
- 0
src/real.cpp View File

@@ -0,0 +1,48 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstring>

#include "core.h"

using namespace std;

namespace lol
{

template<> real4k::Real(float f)
{
union { float f; uint32_t x; } u = { f };

uint32_t sign = u.x & 0x80000000u;
int e = ((u.x >> 23) & 0xff) + (1 << 30) - (1 << 10);

m_signexp = sign | e;
m_mantissa[0] = u.x << 17;
memset(m_mantissa + 1, 0, sizeof(m_mantissa) - sizeof(m_mantissa[0]));
}

template<> real4k::operator float() const
{
union { float f; uint32_t x; } u;

u.x = m_mantissa[0] >> 17;
u.x |= ((m_signexp & 0x7fffffffu) - (1 << 30) + (1 << 10)) << 23;
u.x |= m_signexp & 0x80000000u;

return u.f;
}

} /* namespace lol */


+ 42
- 0
src/real.h View File

@@ -0,0 +1,42 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

//
// The Real class
// --------------
//

#if !defined __LOL_REAL_H__
#define __LOL_REAL_H__

#include <stdint.h>

namespace lol
{

template<int NBITS> class Real
{
public:
inline Real<NBITS>() {}
Real<NBITS>(float f);

operator float() const;

private:
uint32_t m_signexp;
uint32_t m_mantissa[(NBITS + 31) / 32];
};

typedef Real<4096> real4k;

} /* namespace lol */

#endif // __LOL_REAL_H__


+ 1
- 1
test/Makefile.am View File

@@ -19,7 +19,7 @@ noinst_PROGRAMS = quad sandbox benchsuite testsuite
TESTS = testsuite

testsuite_SOURCES = testsuite.cpp \
unit/matrix.cpp unit/half.cpp unit/trig.cpp unit/build.cpp
unit/matrix.cpp unit/half.cpp unit/trig.cpp unit/build.cpp unit/real.cpp
testsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
testsuite_DEPENDENCIES = $(top_builddir)/src/liblol.a


Loading…
Cancel
Save