gzdoom/code/M_fixed.c

67 lines
1.3 KiB
C
Raw Normal View History

1998-04-07 00:00:00 +00:00
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id:$
//
// Copyright (C) 1993-1996 by id Software, Inc.
//
// This source is available for distribution and/or modification
// only under the terms of the DOOM Source Code License as
// published by id Software. All rights reserved.
//
// The source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details.
//
// $Log:$
//
// DESCRIPTION:
// Fixed point implementation.
//
//-----------------------------------------------------------------------------
1998-04-07 00:00:00 +00:00
#include <stdlib.h>
1998-04-07 00:00:00 +00:00
#include "doomtype.h"
#include "i_system.h"
#include "m_fixed.h"
1998-04-07 00:00:00 +00:00
#ifndef USEASM
1998-04-07 00:00:00 +00:00
// C routines
1998-04-07 00:00:00 +00:00
fixed_t FixedMul_C (fixed_t a, fixed_t b)
1998-04-07 00:00:00 +00:00
{
return (fixed_t)(((__int64) a * (__int64) b) >> FRACBITS);
}
1998-04-07 00:00:00 +00:00
fixed_t FixedDiv_C (fixed_t a, fixed_t b)
1998-04-07 00:00:00 +00:00
{
1998-04-07 00:00:00 +00:00
if ((abs (a) >> 14) >= abs (b))
1998-04-07 00:00:00 +00:00
return (a^b)<0 ? MININT : MAXINT;
{
#if 0
long long c;
c = ((long long)a<<16) / ((long long)b);
return (fixed_t) c;
#endif
double c;
c = ((double)a) / ((double)b) * FRACUNIT;
1998-04-07 00:00:00 +00:00
/*
if (c >= 2147483648.0 || c < -2147483648.0)
I_FatalError("FixedDiv: divide by zero");
*/
1998-04-07 00:00:00 +00:00
return (fixed_t) c;
}
}
#endif