Results 1 to 7 of 7

Thread: Single or doubles?

  1. #1

    Single or doubles?

    For my game engine, I'm defining records like TVector, TMatrix, TPoint, TRay, TPlane, and so on, but I don't know whether I should make the the type of their members single or double. I suppose I could define two versions, e.g. TVectors, and TVectord, for single and double, but then, which one do I actually use?

    Related, many OpenGL functions tend to have two versions: one for doubles (glBlahd) and one for floats (glBlahf). Which one should I use in my game engine?
    [size=10px]"In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it's the exact opposite." -- Paul Dirac[/size]

  2. #2

    Single or doubles?

    It doesnt really matter which one you go for, the difference is that a double has more significant digits than a single...

    From the help file:
    Type Range Digits Size (Bytes)
    -----------------------------------------------------------------------------
    Single 1.5 x 10^-45 .. 3.4 x 10^38 7-8 4
    Double 5.0 x 10^-324 .. 1.7 x 10^308 15-16 8
    hope helps
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  3. #3

    Single or doubles?

    But what about speed and memory issues? I think I may define my own type bmFloat, define that to be a Single and profile my program; then I'll define it to be a Double and profile it again; and finally compare results. Trouble with that method is that it's all or nothing. Maybe it makes sense to have some variables be Double and some variables be Single, depending on how they are used, rather than all Single or all Double. I dunno, just thinking out loud.
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

  4. #4

    Single or doubles?

    Commercial games use single precision floats for speed and size reasons. Games do not require the higher precision that doubles give.

  5. #5

    Single or doubles?

    Quote Originally Posted by Sly
    Commercial games use single precision floats for speed and size reasons. Games do not require the higher precision that doubles give.
    Mostly also because 3DNow (and SSE) can pack multiple singles into a double.

    Single takes less memory (thus better cache util), however double is 8 bytes aligned. Hard to say what would be faster, needs profiling

  6. #6

    Single or doubles?

    Code:
    var
      //f, pi&#58; Single;
      i, j, time&#58; Integer;
      f, pi&#58; Double;
    begin
      time &#58;= GetTickCount;
      for j &#58;= 0 to 999999 do
      begin
        pi &#58;= System.Pi;
        f &#58;= 1.0;
        for i &#58;= 0 to 10 do
        begin
          f &#58;= f*pi;
          f &#58;= f*pi;
          f &#58;= f*pi;
          f &#58;= f*pi;
        end;
      end;
      ShowMessage&#40;IntToStr&#40;GetTickCount-time&#41;&#41;;
    This code gave 600ms for Single and 800ms for Double on my machine

  7. #7

    Single or doubles?

    Thanks for your replies everyone.
    [size=10px]&quot;In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it&#39;s the exact opposite.&quot; -- Paul Dirac[/size]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •