Menu

#2 Subtract from variable, cannot subtract bellow 0

open
4
2009-04-18
2009-04-18
No

An access violation ocurs if you subtract from a variable to get a result below -1
For example:

$y:float
$y = -1
$y = $y-1

This should change $y to -2 however it just creates an access voilation.

-- The workaround --
You can avoid this happening by making the subtraction in a slightly different way.
For example:

$y:float
$y = -1
$y = $y+(0-1)

This doesn't fail to execute and you do end up with -2.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.