Syntax Error: rDouble = (iInteger >> 10)

Just starting out? Need help? Post your questions and find answers here.
PeDe
Enthusiast
Enthusiast
Posts: 305
Joined: Sun Nov 26, 2017 3:13 pm

Syntax Error: rDouble = (iInteger >> 10)

Post by PeDe »

PB v6.04/6.12b3, Windows 7

Why does the last line in the code Not work?

Peter

Code: Select all

Define rDouble.d
Define iInteger.i
iInteger = 4096
rDouble = (iInteger / 1024)
rDouble = (4096 >> 10)
rDouble = (iInteger >> 10)

; ---------------------------
; PureBasic
; ---------------------------
; Line 6: Can't use any of the following operands with float or double: <<, >>, &, |, !, %.
; ---------------------------
; OK   
; ---------------------------
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Syntax Error: rDouble = (iInteger >> 10)

Post by Fred »

When assigning to a double, the whole expression is casted to double, even if parenthesis are used. Constants are resolved at compile time, that's why it's a bit different.
PeDe
Enthusiast
Enthusiast
Posts: 305
Joined: Sun Nov 26, 2017 3:13 pm

Re: Syntax Error: rDouble = (iInteger >> 10)

Post by PeDe »

Ok, thanks. I noticed the syntax error with FormatNumber() and I didn't understand it.

Peter
Post Reply