Port overflow fixes for daily interest and dividends; pay Modern dividends per manager
Daily interest and share dividends are computed in 64 bits before the division (ported from OpenBMH 1.0.3). In Modern each manager now receives the dividend of his own shares instead of the original's lost booking. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
f0979455d1
commit
9e92d07b03
10 files changed
+59
-62
No files matched your search
@@ -32,20 +32,14 @@ void daily_interest(ModernState& g, WatcomRandom& rand) {
|
||||
const int32_t balance = rd32(g.manager_records, rec + 0x314);
|
||||
const int32_t deposit = rd32(g.manager_records, rec + 0x318);
|
||||
const int32_t credit = rd32(g.manager_records, rec + 0x31c);
|
||||
int32_t amount = 0; // positive = cost
|
||||
// widened to 64 bits before the division (see daily_interest_amounts)
|
||||
const DailyInterestAmounts interest = daily_interest_amounts(balance, deposit, credit);
|
||||
if (balance < 0) {
|
||||
if (balance + credit < 0) amount = ((balance + credit) * 18) / -36500;
|
||||
int32_t used = -credit < balance ? balance : -credit;
|
||||
amount += (used * 12) / -36500;
|
||||
wr32(g.manager_records, rec + 0x89c, rd32(g.manager_records, rec + 0x89c) + amount);
|
||||
modern::book_money(g, k, amount, true);
|
||||
amount = 0;
|
||||
} else {
|
||||
amount = balance / -36500;
|
||||
wr32(g.manager_records, rec + 0x89c, int32_t(uint32_t(rd32(g.manager_records, rec + 0x89c)) + uint32_t(interest.borrowing)));
|
||||
modern::book_money(g, k, interest.borrowing, true);
|
||||
}
|
||||
amount += ((deposit / 10000) * 20000) / -36500;
|
||||
wr32(g.manager_records, rec + 0x870, rd32(g.manager_records, rec + 0x870) - amount);
|
||||
modern::book_money(g, k, amount, true);
|
||||
wr32(g.manager_records, rec + 0x870, int32_t(uint32_t(rd32(g.manager_records, rec + 0x870)) - uint32_t(interest.cash_and_deposit)));
|
||||
modern::book_money(g, k, interest.cash_and_deposit, true);
|
||||
if (rd32(g.manager_records, rec + 0x314) > 100000000) { // read again after the bookings
|
||||
int32_t extra = int32_t(rand.range(10000, 20000)) * 1000;
|
||||
// BookMoney2 with the statistics flag set: counts as an expense (+0x8a0)
|
||||
|
||||
Reference in new issue
Block a user