Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Type converting..
#1
When you do this:

Code:
dim onebyte as ubyte
onebyte = 255
onebyte +=10

print onebyte

Then onebyte is 9, I understand that this is because of an overflow, but woulden't it be better if it stopped at 255?

Code:
print cubyte(265) 'convert value to a ubyte value
This also returns 9, here at least wouldent it be better if it returned 255?
Reply
#2
If you want it completely different than in any other language and running at 1/5 of the atual speed, yeah.. there's no instruction to do satured operations in most CPU's, but when working with packed data, SIMD, where wrap-around is not always wanted..
Reply
#3
adding numbers is done by the CPU, and its been the same since forever. If you want something different, design your own CPU Wink.
Reply
#4
You could do smth like this:
Code:
declare sub addwith255limit (byref var, val)
   if (int(var) + int(val)) > 255 then exit sub
   var += val
end sub
url]http://fbide.sourceforge.net/[/url]
Reply
#5
Ok I'll stop whining Smile I'll just have to make a function checking the value myself

Quote:adding numbers is done by the CPU, and its been the same since forever. If you want something different, design your own CPU .
hmmm a good idea! Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)