Repository navigation
Conversation
SQR of a negative number (and ASIN/ACOS out of range, EXP overflow, SEC/CSC/COT at their poles) produced NaN or infinity, which FromDouble then failed to parse. The .NET FormatException escaped as "runtime error: Input string was not in a correct format." and could not be handled with WHEN EXCEPTION. SQR now rejects negative arguments with exception 2001, matching LOG, and FromDouble reports NaN as 2001 and infinity as 1001, naming the function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PRINT SQR(-1)printedruntime error: Input string was not in a correct format.Math builtins pass theirdoubleresult throughFromDouble, which parsesd.ToString("R")into aBigDecimal. A NaN or infinite result (SQRof a negative,ASIN/ACOSoutside [-1, 1],EXPoverflow,SEC/CSC/COTat their poles) made that parse throw a .NETFormatException, so the error couldn't be handled withWHEN EXCEPTIONand the message was meaningless.Found while running Arcade BASIC in the browser on adamberent.com.
Fix
SQRrejects negative arguments with exception 2001 ("SQR requires non-negative argument"), the same codeLOGuses for its domain error.FromDoubletakes the function name and reports NaN as 2001 ("ASIN argument out of range") and infinity as 1001 ("EXP result overflows"), the code already used for division by zero.Both engines share
BuiltinImpls, so the tree-walker and the VM behave the same.Tests
Regression theory added to both
ExceptionTests(interpreter) andVmTests:SQR(-1),ASIN(2),ACOS(-2)andEXP(1000)are caught byWHEN EXCEPTIONwith the expectedEXTYPEandEXTEXT$. Full suite: 574 passed; Release build has 0 warnings.🤖 Generated with Claude Code