Before z88dk v2.5, classic `-lm` in these recipes linked genmath (6-byte, sccz80). From v2.5, `-lm` links math32. A 6-byte rerun is `--genmath` or `--math48` with sccz80 or 80cc. zsdcc stores a 4-byte IEEE value. 8-byte Microsoft format is `--mbf64` with either compiler.

CHANGES TO SOURCE CODE
======================

When built with --math16 (__MATH_MATH16), floating types use _Float16,
invsqrtf16/sqrtf16, and DT=1e-1 so intermediate values stay in half range.

VERIFY CORRECT RESULT
=====================

To verify the correct result compile for the zx spectrum target
and run in an emulator.

classic/sccz80
zcc +zx -vn -DSTATIC -DPRINTF -O2 n-body.c -o n-body -lm -lndos -create-app

classic/sccz80/8085/MBF32
zcc +cpm -clib=8085 -vn -DSTATIC -DPRINTF -O2 n-body.c -o n-body --math-mbf32 -lndos -create-app

classic/sccz80/math32
zcc +zx -vn -DSTATIC -DPRINTF -O2 n-body.c -o n-body --math32 -lndos -create-app

classic/sccz80/8085/math32
zcc +cpm -clib=8085 -vn -DSTATIC -DPRINTF -O2 n-body.c -o n-body --math32 -lndos -create-app

classic/sccz80/math16
zcc +zx -vn -DSTATIC -DPRINTF -O3 --opt-code-speed=inlineints n-body.c -o n-body --math16 -lm -lndos -create-app

classic/sccz80/8085/math16
zcc +cpm -clib=8085 -vn -DSTATIC -DPRINTF -O3 --opt-code-speed=inlineints n-body.c -o n-body --math16 -lmath32_8085 -lndos -create-app

classic/zsdcc
zcc +zx -vn -DSTATIC -DPRINTF -compiler=sdcc -SO3 --max-allocs-per-node200000 n-body.c -o n-body -lmath48 -lndos -create-app
first number error : 5 * 10^(-8)
second number error: 1 * 10^(-8)

TIMING
======

To time, the program was compiled for the generic z80 target so that
a binary ORGed at address 0 was produced.

This simplifies the use of TICKS for timing.

classic/sccz80
zcc +test -vn -DSTATIC -DTIMER -D__Z88DK -O2 n-body.c -o n-body.bin -lm -m -lndos

classic/sccz80/MBF32
zcc +test -vn -DSTATIC -DTIMER -D__Z88DK -O2 n-body.c -o n-body.bin --math-mbf32 -m -lndos

classic/sccz80/8085/MBF32
zcc +test -clib=8085 -vn -DSTATIC -DTIMER -D__Z88DK -O2 n-body.c -o n-body.bin --math-mbf32 -m -lndos

classic/sccz80/math32
zcc +test -vn -DSTATIC -DTIMER -D__Z88DK -O2 n-body.c -o n-body.bin --math32 -m -lndos

classic/sccz80/math16
zcc +test -vn -DSTATIC -DTIMER -D__Z88DK -O3 --opt-code-speed=inlineints n-body.c -o n-body.bin --math16 -m -lndos

classic/sccz80/8085/math32
zcc +test -clib=8085 -vn -DSTATIC -DTIMER -D__Z88DK -O2 n-body.c -o n-body.bin --math32 -m -lndos

classic/sccz80/8085/math16
zcc +test -clib=8085 -vn -DSTATIC -DTIMER -D__Z88DK -O3 --opt-code-speed=inlineints n-body.c -o n-body.bin --math16 -lmath32_8085 -m -lndos

classic/80cc/math32
zcc +test -compiler=80cc -vn -DSTATIC -DTIMER -D__Z88DK -O2 n-body.c -o n-body.bin --math32 -m -lndos
# Z80 80cc best case: locals from the stack pointer.

classic/80cc/8085/math32
zcc +test -clib=8085 -compiler=80cc -vn -DSTATIC -DTIMER -D__Z88DK -O2 n-body.c -o n-body.bin --math32 -m -lndos

Note: 80cc math32 TIMER is valid. Do not skip. +test PRINTF of n-body
needs z88dk-ticks -counter larger than the run (default 1e8). The
bare 10000000x line is that cap, not a dead %f. Official verify is
still +zx / +cpm.

classic/zsdcc
zcc +test -vn -DSTATIC -DTIMER -D__Z88DK -compiler=sdcc -SO3 --max-allocs-per-node200000 n-body.c -o n-body.bin -lmath48 -m -lndos

The map file was used to look up symbols "TIMER_START" and "TIMER_STOP".
These address bounds were given to TICKS to measure execution time.

A typical invocation of TICKS looked like this:

z88dk-ticks n-body.bin -x n-body.map -start TIMER_START -end TIMER_STOP -counter 999999999999

For 8085 binaries add -m8085:

z88dk-ticks -m8085 n-body.bin -x n-body.map -start TIMER_START -end TIMER_STOP -counter 999999999999

start   = TIMER_START in hex
end     = TIMER_STOP in hex
counter = High value to ensure completion

If the result is close to the counter value, the program may have
prematurely terminated so rerun with a higher counter if that is the case.

RESULT
======

Z88DK August 16, 2026
zsdcc 4.6.0 #16639 / classic
4962 bytes less page zero

first number error : 5 * 10^(-8)
second number error: 1 * 10^(-8)

cycle count  = 2243368504
time @ 4MHz  = 2243368504 / 4*10^6 =  9 min 21 sec


Z88DK January 3, 2022
sccz80 / classic
4527 bytes less page zero

first number error : 5 * 10^(-8)
second number error: 1 * 10^(-8)

cycle count  = 3659884553
time @ 4MHz  = 3659884553 / 4*10^6 = 15 min 15 sec


Z88DK July 19, 2026
sccz80 / classic / 8085 / MBF32
4729 bytes less page zero

first number error : 1 * 10^(-7)
second number error: 1 * 10^(-4)

cycle count  = 1849800062
time @ 4MHz  = 1849800062 / 4*10^6 =  7 min 42 sec


Z88DK July 19, 2026
sccz80 / classic / MBF32
4956 bytes less page zero

first number error : 1 * 10^(-7)
second number error: 1 * 10^(-4)

cycle count  = 1835079611
time @ 4MHz  = 1835079611 / 4*10^6 =  7 min 39 sec


Z88DK September 17, 2026
sccz80 / classic / math32
5897 bytes less page zero

first number error : 5 * 10^(-8)
second number error: 2 * 10^(-6)

cycle count  = 808246253
time @ 4MHz  = 808246253 / 4*10^6 =  3 min 22 sec


Energy: -0.1690752 / -0.1690861 (N=1000).
Z88DK September 17, 2026
sccz80 / classic / 8085 / math32
6836 bytes less page zero

first number error : 5 * 10^(-8)
second number error: 2 * 10^(-6)

cycle count  = 1488228803
time @ 4MHz  = 1488228803 / 4*10^6 =  6 min 12 sec

Energy: -0.1690752 / -0.1690861 (N=1000).


Z88DK October 15, 2026
80cc / classic / math32
6859 bytes less page zero

cycle count  = 800805511
time @ 4MHz  = 800805511 / 4*10^6 =  3 min 20 sec


Z88DK October 15, 2026
80cc / classic / 8085 / math32
7629 bytes less page zero

cycle count  = 1460762215
time @ 4MHz  = 1460762215 / 4*10^6 =  6 min  5 sec


Z88DK September 17, 2026
sccz80 / classic / math16
4124 bytes less page zero

cycle count  = 295229389
time @ 4MHz  = 295229389 / 4*10^6 =  1 min 14 sec

IEEE 16-bit half-float (math16). DT=1e-1 for half range.


Z88DK September 17, 2026
sccz80 / classic / 8085 / math16
4174 bytes less page zero

cycle count  = 348032655
time @ 4MHz  = 348032655 / 4*10^6 =  1 min 27 sec

IEEE 16-bit half-float (math16_8085). DT=1e-1 for half range.
