Code Search for Developers
 
 
  

exfixed.c from Allegro game programming library at Krugle


Show exfixed.c syntax highlighted

/*
 *    Example program for the Allegro library, by Shawn Hargreaves.
 *
 *    This program demonstrates how to use fixed point numbers.
 */


#include <stdio.h>

#include "allegro.h"



int main()
{
   /* declare three 32 bit (16.16) fixed point variables */
   fixed x, y, z;

   allegro_init();

   /* convert integers to fixed point like this */
   x = al_int_to_fix(10);

   /* convert floating point to fixed point like this */
   y = al_float_to_fix(3.14);

   /* fixed point variables can be assigned, added, subtracted, negated,
    * and compared just like integers, eg: 
    */
   z = x + y;
   al_show_message("%f + %f = %f\n", al_fix_to_(x), al_fix_to_(y), al_fix_to_(z));

   /* you can't add integers or floating point to fixed point, though:
    *    z = x + 3;
    * would give the wrong result.
    */

   /* fixed point variables can be multiplied or divided by integers or
    * floating point numbers, eg:
    */
   z = y * 2;
   al_show_message("%f * 2 = %f\n", al_fix_to_(y), al_fix_to_(z));

   /* you can't multiply or divide two fixed point numbers, though:
    *    z = x * y;
    * would give the wrong result. Use al_fix_mul() and al_fix_div() instead, eg:
    */
   z = al_fix_mul(x, y);
   al_show_message("%f * %f = %f\n", al_fix_to_(x), al_fix_to_(y), al_fix_to_(z));

   /* fixed point trig and square root are also available, eg: */
   z = al_fix_sqrt(x);
   al_show_message("al_fix_sqrt(%f) = %f\n", al_fix_to_(x), al_fix_to_(z));

   return 0;
}

AL_END_OF_MAIN();




See more files for this project here

Allegro game programming library

Allegro is a cross-platform library intended for use in computer games and other types of multimedia programming.

Project homepage: http://sourceforge.net/projects/alleg
Programming language(s): Assembly,C,Shell Script
License: other

  allegro.pcx
  ex12bit.c
  ex3buf.c
  ex3d.c
  exaccel.c
  exalpha.c
  example.dat
  example.h
  examples.txt
  exbitmap.c
  exblend.c
  excamera.c
  excolmap.c
  excustom.c
  exdata.c
  exdbuf.c
  exdodgy.c
  exexedat.c
  exfixed.c
  exflame.c
  exflip.c
  exgui.c
  exhello.c
  exjoy.c
  exkeys.c
  exlights.c
  exmem.c
  exmidi.c
  exmouse.c
  expal.c
  expat.c
  exquat.c
  exrgbhsv.c
  exsample.c
  exscale.c
  exscn3d.c
  exscroll.c
  exshade.c
  exspline.c
  exsprite.c
  exstars.c
  exstream.c
  exswitch.c
  extimer.c
  extrans.c
  extruec.c
  exunicod.c
  exupdate.c
  exxfade.c
  exzbuf.c
  mysha.pcx
  planet.pcx
  running.dat
  running.h
  unifont.dat