Compare commits

..
2 Commits
Author SHA1 Message Date
ClaudeandClaude Sonnet 5.5 aa6ec96305 Prepare Classic 1.0.8 patch release
Prepare verified release / draft (push) Waiting to run
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 22:05:19 +01:00
ClaudeandClaude Sonnet 5.5 e337c3c6b2 Bank credit annuity: evaluate the original's x87 rounding chain exactly
The original computes ((base / 100) * den) / 100 with 64-bit-mantissa x87
steps and one final store to a double. The host long double is only 64 bits
wide on MSVC and Apple silicon, so the annuity differed by 1 for roughly 0.2 %
of realistic loans (1-60 million) there. The chain is now evaluated with
integers, identical on every platform. Verified against the original routine
in an emulator: 5684 term/principal combinations, no difference.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 21:40:20 +01:00
5 changed files with 148 additions and 13 deletions

No files matched your search

+1 -1
View File
@@ -62,4 +62,4 @@ jobs:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.ref_name }}
run: |
gh release create "$RELEASE_TAG" dist/*.zip dist/SHA256SUMS dist/QA-REPORT.json --draft --verify-tag --title "OpenBMH $RELEASE_TAG" --notes-file docs/release/1.0.7/RELEASE_NOTES.md
gh release create "$RELEASE_TAG" dist/*.zip dist/SHA256SUMS dist/QA-REPORT.json --draft --verify-tag --title "OpenBMH $RELEASE_TAG" --notes-file docs/release/1.0.8/RELEASE_NOTES.md
+1 -1
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-only
cmake_minimum_required(VERSION 3.24)
project(OpenBMH VERSION 1.0.7 LANGUAGES CXX C)
project(OpenBMH VERSION 1.0.8 LANGUAGES CXX C)
if(APPLE)
# Enable native languages before dependencies/subdirectories inherit rules.
enable_language(OBJC OBJCXX)
+2 -2
View File
@@ -1,6 +1,6 @@
# OpenBMH
**Classic-Version: 1.0.7.** Die originalgetreue Linie bleibt in diesem Repository.
**Classic-Version: 1.0.8.** Die originalgetreue Linie bleibt in diesem Repository.
Erweiterte Ligen, die gemeinsame deutsche/englische Karriere und der Dateneditor
werden separat als **[OpenBMH-Extended 1.0 Beta](https://github.com/Weyoune/OpenBMH-extended)** entwickelt.
@@ -30,7 +30,7 @@ In Windows PowerShell, use `.\OpenBMH.exe` and `.\openbmh_cli.exe` instead.
To report a problem, start the game with `-debug`. It then writes `openbmh-debug.log` (timestamped events, errors and refused actions) and `openbmh-stderr.log` into the `debug` sub folder of the save directory, and saves the game there after every match day (`DBG00001.FBM`, `DBG00002.FBM`, ...). Attach the log and the last save to the report.
Use a writable save directory and keep backups of existing games. German editions are the primary compatibility target. **Football Limited / English data support is experimental**; original V2.20 save import and some edition-specific behaviour remain limited. See the [release notes](docs/release/1.0.7/RELEASE_NOTES.md).
Use a writable save directory and keep backups of existing games. German editions are the primary compatibility target. **Football Limited / English data support is experimental**; original V2.20 save import and some edition-specific behaviour remain limited. See the [release notes](docs/release/1.0.8/RELEASE_NOTES.md).
## Features and direction
+43
View File
@@ -0,0 +1,43 @@
# OpenBMH Classic 1.0.8
This patch makes the bank credit annuity identical on every platform. It
requires the player's own game installation. Extended development remains
separate in [OpenBMH-Extended](https://github.com/Weyoune/OpenBMH-extended).
## Changes since 1.0.7
- **Bank credit annuity.** The original computes the monthly payment with
x87 floating point (64-bit mantissa at every step, one final store to a
double). The host `long double` is only 64 bits wide on Windows (MSVC) and
on Apple silicon, so the payment differed by 1 for roughly 0.2 % of loans of
one to sixty million. The chain is now evaluated with integer arithmetic and
gives the original's result on every platform.
## Validation and human QA
Release publication requires successful Windows x64, macOS ARM64 and Linux x64
builds, configured tests, product-version checks and package/source verification
for the exact tagged revision. Downloads include checksums, a platform test
report and corresponding source with pinned open-source dependencies.
This release follows a quality pass that ran single routines of the original
programme in an emulator and compared them with the engine on whole savegames,
with boundary values and a deliberately wrong result per rule that must fail.
Compared without a difference: the random generator, market value and salary,
the willingness of clubs to sell, the rating of transfer bids, club mood and
flags at the end of a season, the order of national cup ties, weekly advertising
offers, facility ageing and damage, offers to managers, weekly statistics,
familiarity decay, squad training and daily interest. The one difference found
is the annuity fixed above. Rules that depend on screens, dialogs or the master
database were not part of this pass.
Native Windows/macOS gameplay acceptance is not established by CI builds. Open
points from earlier releases remain: the "player card: original atlas bounds"
error (#77), sporadic double clicks (#58) and the macOS match scene speed (#70).
## Known limits
The compatibility and long-career limits documented for
[1.0.3](../1.0.3/RELEASE_NOTES.md) remain. Football Limited is experimental;
its original V2.20 save layout remains unsupported. Keep backups of saves.
macOS packages are unsigned terminal executables, not notarised app bundles.
+101 -9
View File
@@ -2,6 +2,7 @@
#include "formats/executable_layout.hpp"
#include "game/bank_credit.hpp"
#include <array>
#include <bit>
#include <cmath>
#include <cstring>
@@ -29,6 +30,102 @@ uint32_t read_record(const GameState& g, size_t at) {
for (int i = 0; i < 4; ++i) v |= uint32_t(g.manager_records.at(at + i)) << (i * 8);
return v;
}
// The original evaluates ((base / 100) * den) / 100 on the x87 stack: every step is rounded to a
// 64-bit mantissa (round to nearest even), only the final store rounds to a 53-bit double. The
// host's long double is not that format (64 bits on MSVC and on Apple silicon), which changed the
// result by 1 for loans of about a million and more. This evaluates the same chain exactly with
// integers, so the result is the same on every platform. Returns the value truncated toward zero.
struct Wide { // 128-bit unsigned, little-endian 32-bit limbs
std::array<uint32_t, 4> l{};
unsigned bit_length() const {
for (int i = 3; i >= 0; --i)
if (l[size_t(i)]) return unsigned(i) * 32 + unsigned(32 - std::countl_zero(l[size_t(i)]));
return 0;
}
bool bit(unsigned n) const { return n < 128 && (l[n / 32] >> (n % 32)) & 1u; }
bool any_below(unsigned n) const { // any bit below position n set
for (unsigned i = 0; i < n && i < 128; ++i) if (bit(i)) return true;
return false;
}
static Wide from(uint64_t v) { Wide w; w.l[0] = uint32_t(v); w.l[1] = uint32_t(v >> 32); return w; }
uint64_t window(unsigned lo) const { // the 64 bits starting at bit `lo`
uint64_t v = 0;
for (unsigned i = 0; i < 64; ++i) if (bit(lo + i)) v |= uint64_t(1) << i;
return v;
}
};
struct Extended { uint64_t m = 0; int e = 0; }; // value = m * 2^e, m has 64 bits (or is zero)
// Round `w` (plus a "something was dropped" flag) to 64 bits, nearest even; value = w * 2^exp.
Extended round_to_64(const Wide& w, bool sticky, int exp) {
const unsigned len = w.bit_length();
Extended r;
if (len == 0) return r;
if (len <= 64) {
const unsigned up = 64 - len;
r.m = w.window(0) << up;
r.e = exp - int(up);
return r;
}
const unsigned s = len - 64;
r.m = w.window(s);
const bool guard = w.bit(s - 1), rest = sticky || w.any_below(s - 1);
r.e = exp + int(s);
if (guard && (rest || (r.m & 1))) {
if (++r.m == 0) { r.m = uint64_t(1) << 63; ++r.e; }
}
return r;
}
Extended x87_divide_small(const Extended& a, uint32_t d) {
Wide n; // a.m * 2^64, divided limb by limb
n.l[2] = uint32_t(a.m); n.l[3] = uint32_t(a.m >> 32);
uint64_t rem = 0;
Wide q;
for (int i = 3; i >= 0; --i) {
const uint64_t cur = (rem << 32) | n.l[size_t(i)];
q.l[size_t(i)] = uint32_t(cur / d);
rem = cur % d;
}
return round_to_64(q, rem != 0, a.e - 64);
}
Extended x87_multiply_small(const Extended& a, uint32_t b) {
Wide p;
uint64_t carry = 0;
const uint32_t limb[2] = {uint32_t(a.m), uint32_t(a.m >> 32)};
for (int i = 0; i < 2; ++i) {
const uint64_t cur = uint64_t(limb[i]) * b + carry;
p.l[size_t(i)] = uint32_t(cur);
carry = cur >> 32;
}
p.l[2] = uint32_t(carry);
return round_to_64(p, false, a.e);
}
// ((base / 100) * den) / 100 stored as a double and truncated toward zero. `zero` reports an exact
// zero before truncation (the original's "exact zero becomes 1" rule looks at the stored double).
int64_t x87_amount_chain(int32_t base, uint32_t den, bool& zero) {
zero = base == 0 || den == 0;
if (zero) return 0;
const bool negative = base < 0;
const uint64_t magnitude = negative ? uint64_t(-int64_t(base)) : uint64_t(base);
Extended v = round_to_64(Wide::from(magnitude), false, 0);
v = x87_divide_small(v, 100);
v = x87_multiply_small(v, den);
v = x87_divide_small(v, 100);
// store as double: 53-bit mantissa, nearest even
uint64_t m53 = v.m >> 11;
int e = v.e + 11;
const bool guard = (v.m >> 10) & 1, rest = (v.m & 0x3ff) != 0;
if (guard && (rest || (m53 & 1))) ++m53; // a carry to 2^53 is still exact
uint64_t whole;
if (e >= 0) {
if (e > 10) throw std::invalid_argument("invalid native credit amount");
whole = m53 << e;
} else {
whole = -e >= 64 ? 0 : m53 >> unsigned(-e);
}
if (whole > uint64_t(std::numeric_limits<int32_t>::max()) + (negative ? 1u : 0u))
throw std::invalid_argument("invalid native credit amount");
return negative ? -int64_t(whole) : int64_t(whole);
}
// Amount: signed IMUL/IDIV, x87 intermediate, QWORD store,
// exact-zero floor, then Amount2's explicit rounding toward zero.
int32_t amount(const BankCreditContext& c, uint32_t months, int32_t principal) {
@@ -37,15 +134,10 @@ int32_t amount(const BankCreditContext& c, uint32_t months, int32_t principal) {
const int32_t factor = c.rate_table[months];
const int32_t base = divide(mul(principal, factor), 100);
const int32_t den = divide(10000, factor - 100);
const long double intermediate = (static_cast<long double>(base) / c.divisor)
* den / c.divisor;
double raw = static_cast<double>(intermediate);
if (raw == 0 && principal != 0) raw = 1;
raw = std::trunc(raw);
if (!std::isfinite(raw) || raw < std::numeric_limits<int32_t>::min()
|| raw > std::numeric_limits<int32_t>::max())
throw std::invalid_argument("invalid native credit amount");
return static_cast<int32_t>(raw);
bool zero = false;
int64_t result = x87_amount_chain(base, uint32_t(den), zero);
if (zero && principal != 0) result = 1;
return static_cast<int32_t>(result);
}
void balance(const BankCreditContext& c, BankCreditDraft& d) {
int32_t result = add(c.cash, signed_word(d.values[0]));