Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const: Negation should work with floating point values #560

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion source/utilities/const_eval.bas
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,13 @@ FUNCTION Unary& (exp$, state AS ParserState)

IF Exponent&(exp$, state) = 0 THEN FixupErrorMessage state, "-": EXIT FUNCTION

IF ele$ = "-" THEN ParseNumSetI state.num, INTEGER64TYPE - ISPOINTER, -state.num.i
IF ele$ = "-" THEN
IF state.num.typ AND ISFLOAT THEN
ParseNumSetF state.num, FLOATTYPE - ISPOINTER, -state.num.f
ELSE
ParseNumSetI state.num, INTEGER64TYPE - ISPOINTER, -state.num.i
END IF
END IF
Unary& = -1
IF CONST_EVAL_DEBUG THEN _ECHO "Unary done!"
END FUNCTION
Expand Down
4 changes: 4 additions & 0 deletions tests/compile_tests/const/expression.bas
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ CONST const__unsignedint = 2~&& * 5~&&

CONST const__division_floating = 1& / 5&

CONST const__negate_floating = -.25!

PRINT const__OR
PRINT const__AND
PRINT const__NOT
Expand Down Expand Up @@ -95,4 +97,6 @@ PRINT const__unsignedint

PRINT const__division_floating

PRINT const__negate_floating

SYSTEM
1 change: 1 addition & 0 deletions tests/compile_tests/const/expression.output
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ foobarfoobarfoobar2
foobarfoobarfoobar2
10
.2
-.25
Loading