Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions PureDOOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -21222,15 +21222,27 @@ fixed_t FixedDiv(fixed_t a, fixed_t b)
}


// Define DOOM_NO_FLOATING_POINT to disable use of floating point.
fixed_t FixedDiv2(fixed_t a, fixed_t b)
{
#if defined(DOOM_NO_FLOATING_POINT)
// Integer-only rewrite of the original double-precision version
long long c;

c = ((long long)a << FRACBITS) / (long long)b;

if (c >= 2147483648LL || c < -2147483648LL)
I_Error("Error: FixedDiv: divide by zero");
return (fixed_t)c;
#else
double c;

c = ((double)a) / ((double)b) * FRACUNIT;

if (c >= 2147483648.0 || c < -2147483648.0)
I_Error("Error: FixedDiv: divide by zero");
return (fixed_t)c;
#endif
}
#define SAVESTRINGSIZE 24
#define SKULLXOFF -32
Expand Down
12 changes: 12 additions & 0 deletions src/DOOM/m_fixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ fixed_t FixedDiv(fixed_t a, fixed_t b)
}


// Define DOOM_NO_FLOATING_POINT to disable use of floating point.
fixed_t FixedDiv2(fixed_t a, fixed_t b)
{
#if defined(DOOM_NO_FLOATING_POINT)
// Integer-only rewrite of the original double-precision version
long long c;

c = ((long long)a << FRACBITS) / (long long)b;

if (c >= 2147483648LL || c < -2147483648LL)
I_Error("Error: FixedDiv: divide by zero");
return (fixed_t)c;
#else
double c;

c = ((double)a) / ((double)b) * FRACUNIT;

if (c >= 2147483648.0 || c < -2147483648.0)
I_Error("Error: FixedDiv: divide by zero");
return (fixed_t)c;
#endif
}