Skip to content

Commit

Permalink
Calculator: Fix base prefix logic for zero results (#10778)
Browse files Browse the repository at this point in the history
Previously, `/calculate` would fail to include the correct base prefix (`0x`, `0b`, `0o`) when the result was `0` because the code used a falsy check (`if (result)`). This commit replaces that condition with `if (Number.isFinite(result))`, ensuring zero is properly displayed in the requested base.
  • Loading branch information
DieterReinert authored Jan 4, 2025
1 parent d0e1b68 commit 31934d7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion server/chat-plugins/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const commands: Chat.ChatCommands = {
const [result, inferredBase] = solveRPN(parseMathematicalExpression(expression));
if (!base) base = inferredBase;
let baseResult = '';
if (result && base !== 10) {
if (Number.isFinite(result) && base !== 10) {
baseResult = `${BASE_PREFIXES[base]}${result.toString(base).toUpperCase()}`;
if (baseResult === expression) baseResult = '';
}
Expand Down

0 comments on commit 31934d7

Please sign in to comment.