delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/13/20:59:07

Message-Id: <199903140158.UAA32186@delorie.com>
Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: "George Foot" <george DOT foot AT merton DOT ox DOT ac DOT uk>
To: Ishpeck <ishpeck AT xoommail DOT com>
Date: Sun, 14 Mar 1999 01:56:36 +0000
MIME-Version: 1.0
Subject: Re: Help: Allegro Fixed Variable Math. . . .
CC: djgpp AT delorie DOT com
X-mailer: Pegasus Mail for Win32 (v2.42a)
Reply-To: djgpp AT delorie DOT com

On 13 Mar 99 at 10:55, Ishpeck wrote:

> I keep getting weird numbers whenever I use Fixed Variables.... they
> read something like .0076812 when I try to add 1.  I've tried many
> converting an integer using itofix and fadd. . . but, it just won't
> cooperate.  Is there something special about Fixed vars that I'm
> supposed to know?

Please read the Allegro documentation about them, it's quite 
clear.  To add an 
integer to a fixed point number you must pass the integer 
through `itofix' first.

    my_fixed += itofix(1);

You said that you had already tried this; what went wrong when
you did?  Please post a complete but short (no more than
fifteen lines) program that doesn't do what you think it
should, and tell us what you think it should do and what it
actually did.  Here's my program, which prints what I expect it 
to (i.e. `1.000000'):

    #include <allegro.h>
    
    int main (void)
    {
            fixed my_fixed = itofix(0);
            my_fixed += itofix(1);
            printf ("%f\n", fixtof(my_fixed));
            return 0;
    }

-- 
George

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019