According to the Doc's (Yes Geoff, I've read them <g>) , Prog.Guide page 303
a DWORD is an unsigned 32 bit integer. In my opinion that means that the
maximum value I can put into it is 2^32 - 1.
If I type the following:
dwVar := 2^32 - 1
the compiler tells me that I have a possible dangerous conversion between a
Float/Real and a Numeric. The maximum constant I can assign to a DWORD is
2^30 + 99999999.
It's not a big showstopper and can of course be worked around but does
anybody know why this happens and whether or not this is the expected
behaviour.
TIA
Patrick
The maximum value in a DWORD is 3^32-1, or 4294967295, or 0xFFFFFFFF
Try this code instead:
LOCAL nVal AS DWORD
nVal := DWORD(2^32-1)
?nVal // prints 4294967295
The expression 2^32 gives a FLOAT.
--
Regards,
Lars-Eric
http://www.clippersweden.se
Patrick Vletter <p.vl...@cable.a2000.nl> skrev i
diskussionsgruppsmeddelandet:85g99o$rt0$1...@weber.a2000.nl...
> dwVar := 2^32 - 1
> the compiler tells me that I have a possible dangerous conversion between
a
> Float/Real and a Numeric. The maximum constant I can assign to a DWORD is
> 2^30 + 99999999.
Hey, that's nothing - if I do (2^30)*2, I get the warning "Negative value
not allowed".
I suspect the answer to both problems is that the compiler uses LONGs for
integer calculations, so errors will occur if your result > MAX(LONG).
Mike
And yep! the docs to my rescue!
Check out page 308 of the Programmer's guide and you will see the maximum
value for DWORD is 4,294,967,295. So, when the compiler reaches your
expression, it evaluates 2^32 and determines that is REAL and issues you a
warning. Of course you could lower the warning status or type cast the
computation: ie
dwVar := DWORD(2^32 - 1)
By the way, there are some errors on this page of the manual. Sandy Hood has
the correct interpretation for REAL and FLOAT range values:
REAL4 also has 15 significant digits
FLOAT has a range +/- 1.2 * 10 ^ +/- 4932
Geoff
Patrick Vletter <p.vl...@cable.a2000.nl> wrote in message
news:85g99o$rt0$1...@weber.a2000.nl...
> At the risk of being called very stupid for the rest of my career I have a
> very basic question for you all.
>
> According to the Doc's (Yes Geoff, I've read them <g>) , Prog.Guide page
303
> a DWORD is an unsigned 32 bit integer. In my opinion that means that the
> maximum value I can put into it is 2^32 - 1.
>
> If I type the following:
>
> dwVar := 2^32 - 1
>
> the compiler tells me that I have a possible dangerous conversion between
a
> Float/Real and a Numeric. The maximum constant I can assign to a DWORD is
> 2^30 + 99999999.
>
Thanks for your answers.
Of course you are right when you say that 2^32 does not fit in a DWord. So
indeed (2^32 -1) has to be typecasted. But now let's try with 2^31. That
one should fit, but it doen't. Of course it could be type casted too. The
question still stands, what is the limit a a constant that can be assigned
to a
DWord, and why?
While trying I came up with the following examples:
Just look at them and try to explain why things are the way they are:
dwVar := 2^30 + 99999999 -> Works fine
dwVar := 2^30 + 100000000 -> Gives me a compiler warning
dwVar := 2^30 + 99999999 + 2 -> Works fine again
dwVar := 2^30 + 100000000L -> Gives me a compiler ERROR
dwVar := 2^30 + DWORD(100000000) -> Works fine
I'm afraid the docs aren't totally accurate here and that Mike' suggestion
that is has to do with VO using LONG's internally instead of DWORD's is
probably right.
Regards,
Patrick
I know that but 2^31 also gives me a float. That's not a big problem when
one is assigning constants to a DWORD and when the result of a calculation
(and all of it's elements) is smaller than 2^32 the value is correclty
assigned to the DWORD variabable.
There is actually no real problem although in my opinion VO seems to behave
'strange' here.
Regards,
Patrick
Lars-Eric Gisslén wrote in message ...
>Patrick,
>
>The maximum value in a DWORD is 3^32-1, or 4294967295, or 0xFFFFFFFF
>
>Try this code instead:
>LOCAL nVal AS DWORD
>
>nVal := DWORD(2^32-1)
>?nVal // prints 4294967295
>
>The expression 2^32 gives a FLOAT.
>
>--
>Regards,
>Lars-Eric
>http://www.clippersweden.se
>
>Patrick Vletter <p.vl...@cable.a2000.nl> skrev i
>diskussionsgruppsmeddelandet:85g99o$rt0$1...@weber.a2000.nl...
> According to the Doc's (Yes Geoff, I've read them <g>) , Prog.Guide page 303
> a DWORD is an unsigned 32 bit integer. In my opinion that means that the
> maximum value I can put into it is 2^32 - 1.
>
> If I type the following:
>
> dwVar := 2^32 - 1
>
> the compiler tells me that I have a possible dangerous conversion between a
> Float/Real and a Numeric. The maximum constant I can assign to a DWORD is
> 2^30 + 99999999.
The expression 2^32 - 1 will return a float value. To assign that value to the
Dword you should write:
dwVar := 0xFFFFFFFF // hex notation
Robert van der Hulst
here comes my 2 cents...
Isn't it so that the limit for assigning a constant to a Dword in VO is
pretty obvious that it is 0xFFFFFFFF? But what you are doing is
assigning it a value from an expression. And since the parameters of the
arithmetic functions of VO is declared as Usual you run into some
problems. That because of the fact that the usual type for Byte, Word,
DWord, ShortInt, Int and LongInt is LongInt. So it is important to be
careful when you use large Dword declared variables in VO functions
(usual declared) since the computation is done as LongInt.
HTH
Rickard ;-)
> Of course you are right when you say that 2^32 does not fit in a
DWord. So
> indeed (2^32 -1) has to be typecasted. But now let's try with 2^31.
That
> one should fit, but it doen't. Of course it could be type casted too.
The
> question still stands, what is the limit a a constant that can be
assigned
> to a
> DWord, and why?
> While trying I came up with the following examples:
>
> Just look at them and try to explain why things are the way they are:
>
> dwVar := 2^30 + 99999999 -> Works fine
> dwVar := 2^30 + 100000000 -> Gives me a compiler
warning
> dwVar := 2^30 + 99999999 + 2 -> Works fine again
> dwVar := 2^30 + 100000000L -> Gives me a compiler ERROR
> dwVar := 2^30 + DWORD(100000000) -> Works fine
>
> I'm afraid the docs aren't totally accurate here and that Mike'
suggestion
> that is has to do with VO using LONG's internally instead of DWORD's
is
> probably right.
Sent via Deja.com http://www.deja.com/
Before you buy.
I think you have hit the nail on the head!
<ri...@my-deja.com> wrote in message news:85i8qm$5qe$1...@nnrp1.deja.com...
That's probably it!
Isn't this NG a wonderfull platform!
Thanks Richard
ri...@my-deja.com wrote in message <85i8qm$5qe$1...@nnrp1.deja.com>...