Skip to content

API: skillMaxUpgradeCount returns 1 when SP is too small and current level is too high #1693

Open
@catloversg

Description

#1475 added skillMaxUpgradeCount formula API.

When the skill point (SP) is not enough to upgrade the skill, this API should return 0. However, due to floating-point imprecision, when SP is too small and the current level is too high, this API may return 1. For example:

ns.print(ns.formulas.bladeburner.skillMaxUpgradeCount("Hyperdrive", 1e50, 1)); // Print 1

This is how we are implementing it:

const result = Math.round((m + delta) / this.costInc);
const costOfResultPlus1 = this.calculateCost(currentLevel, (result + 1) as PositiveInteger);
if (costOfResultPlus1 <= cost) {
  return result + 1;
}
const costOfResult = this.calculateCost(currentLevel, result as PositiveInteger);
if (costOfResult <= cost) {
  return result;
}
return result - 1;

result is 0, cost is 1, and costOfResultPlus1 is 0, so it returns 1. In this case, the current level is too high (1e50), so increasing it by 1 (result + 1) won't do anything (costOfResultPlus1 = 0) (if the player calls ns.bladeburner.upgradeSkill with count = 1, we will notify them that it's impossible to do that).

At first glance, I think that this behavior is (somewhat ?) reasonable. However, some players may be confused: "Why does it return 1 when it's obvious that I won't be able to upgrade the skill with that amount of SP?".

@d0sboots What do you think about this problem? It only matters when the player is farming int and they don't know the pitfall of floating-point imprecision (A(big) + B(small) may be exactly A in some cases), so I don't think that it's a big deal.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions