Skip to content

Commit

Permalink
trying to fix fixedmul
Browse files Browse the repository at this point in the history
  • Loading branch information
neozeed committed Apr 14, 2024
1 parent 6d1be5f commit a340ea3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
19 changes: 6 additions & 13 deletions m_fixed.c
Expand Up @@ -37,9 +37,7 @@ rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";




// Fixme. __USE_C_FIXED__ or something.

fixed_t
FixedMul
( fixed_t a,
Expand All @@ -49,26 +47,21 @@ FixedMul
#if __WATCOMC__ > 1200
return ((long long) a * (long long) b) >> FRACBITS;
#else
int ah,al,bh,bl,result;
/* overflow? underflow? */
if ( (abs(a)>>14) >= abs(b)) {
return (a^b)<0 ? MININT : MAXINT;
}
ah = (a >> FRACBITS);
al = (a & (FRACUNIT-1));
bh = (b >> FRACBITS);
bl = (b & (FRACUNIT-1));
int ah = (a >> FRACBITS);
int al = (a & (FRACUNIT-1));
int bh = (b >> FRACBITS);
int bl = (b & (FRACUNIT-1));

// Multiply the parts separately
result = (ah * bh) << FRACBITS; // High*High
int result = (ah * bh) << FRACBITS; // High*High
result += ah * bl; // High*Low
result += al * bh; // Low*High
// Low*Low part doesn't need to be calculated because it doesn't contribute to the result after shifting

// Shift right by FRACBITS to get the fixed-point result
result += (al * bl) >> FRACBITS;

return (fixed_t)result;
return result;
#endif
}

Expand Down
1 change: 0 additions & 1 deletion m_fixed.h
Expand Up @@ -59,7 +59,6 @@ fixed_t FixedDiv2 (fixed_t a, fixed_t b);
modify exact [eax edx]
#endif


#endif
//-----------------------------------------------------------------------------
//
Expand Down

1 comment on commit a340ea3

@neozeed
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it doesnt work

fixedmul-malfunction.mp4

Please sign in to comment.