Files
TeslaRel410/BORLAND/BC45/SOURCE/RTL/SOURCE/MATHLIB/FMOD.CAS
T
CydandClaude Fable 5 63312e07f9 source410: literal 4.10 source reconstruction + BC++ 4.52 fleet toolchain archived
- BORLAND/: Borland C++ 4.52 (chosen over 4.5 by byte-match: CODE/RP/CW32.LIB
  is identical to 4.52's install lib). BCC32/TLINK32/TLIB/MAKE run natively on
  Win11; CODE/BT/OPT.MAK is the shipped BTL4OPT.EXE's exact flag recipe
  (extender = Borland PowerPack DPMI32, not Phar Lap TNT).
- restoration/source410/: the literal 1995-form reconstruction of the missing
  BT game source (never mixed into CODE/). Round 1-3 state:
  * 6 of 10 surviving original TUs COMPILE CLEAN under the period toolchain
    (BTMSSN, BTCNSL, BTSCNRL, BTTEAM, BTL4MODE, BTL4ARND) - first builds
    since 1996.
  * BT_L4/BTL4APP.CPP pilot reconstruction: 12/12 functions, Fail() lands on
    its binary-recorded line 400 exactly.
  * BT/BTCNSL.HPP: console wire IDs recovered from the binary's ctors
    (Killed=9, Damaged=10, ScoreUpdate=13, DeathWithoutHonor=15 [T1];
    TeamScore=12 flagged [T4]).
  * MUNGA/: 8 engine-header backfills back-dated from the BT412 WinTesla tree
    (VDATA numbering decomp-verified; AUDREND's OpenAL-era virtual removed -
    the period compiler is the drift detector).
  * Tooling: backdate.py (WinTesla->1995 header transform), compile410.sh
    (per-TU verification sweep under authentic OPT.MAK flags).
  * README: corrected roadmap - MECH.HPP is the capstone grown with the mech
    TU reconstructions; BTREG.CPP green = the header-family milestone.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 07:33:26 -05:00

96 lines
2.6 KiB
Plaintext

/*------------------------------------------------------------------------
* filename - fmod.cas
*
* function(s)
* fmod - calculates x modulo y, the remainder of x/y
*-----------------------------------------------------------------------*/
/*
* C/C++ Run Time Library - Version 6.5
*
* Copyright (c) 1987, 1994 by Borland International
* All Rights Reserved.
*
*/
#pragma inline
#include <asmrules.h>
#include <_math.h>
#include <math.h>
/*--------------------------------------------------------------------------*
Name fmod - calculates x modulo y, the remainder of x/y
Usage double fmod(double x, double y);
Prototype in math.h
Description fmod calculates x - (y * chop (x / y));
This difference can be more accurately calculated using the
FPREM instruction in a repeat loop, though it is slower if
x/y is large.
while (not finished) result = fprem (x, y)
Return value fmod returns x modulo y as described
*---------------------------------------------------------------------------*/
double _FARFUNC fmod (double x, double y)
{
asm FLD DOUBLE (y)
asm mov ax, y [6]
asm shl ax, 1 /* ignore the sign bit */
asm jz mod_resultZero /* if the divisor is zero */
asm cmp ax, 0FFE0h
asm jnb mod_isX /* if y is infinite */
asm FLD DOUBLE (x)
asm mov ax, x [6]
asm shl ax, 1
asm jz mod_xZero /* if x is zero */
asm cmp ax, 0FFE0h
asm jnb mod_overflow /* if x is infinite */
mod_keepTrying:
asm FPREM
asm push bx
asm mov bx, sp
asm FSTSW W0 (SS_ [bx]) /* C2 will be set if not yet finished */
asm FWAIT
asm pop ax
asm sahf
asm jp mod_keepTrying /* C2 bit maps onto parity flag. */
asm FSTP st(1) /* discard the divisor */
mod_end:
#pragma noretval
return;
/*
If the divisor is infinite then return the dividend.
*/
mod_isX:
asm FSTP st(0) /* pop y off the stack */
asm FLD DOUBLE (x)
asm jmp short mod_end
/* All other forms of overflow are mapped onto zero.
*/
mod_xZero:
mod_overflow:
asm FSTP st(0) /* pop x off the stack */
mod_resultZero:
asm FSTP st(0) /* pop y off the stack */
asm FLDZ
asm jmp short mod_end
#pragma warn -rvl
}
#pragma warn .rvl