Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #5283 > unrolled thread
| Started by | kvstegemann@web.de |
|---|---|
| First post | 2013-05-27 08:53 -0700 |
| Last post | 2013-05-31 03:43 -0700 |
| Articles | 20 on this page of 24 — 8 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
Shortint calculations kvstegemann@web.de - 2013-05-27 08:53 -0700
Re: Shortint calculations Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> - 2013-05-27 18:09 +0200
Re: Shortint calculations dlzc <dlzc1@cox.net> - 2013-05-27 10:21 -0700
Re: Shortint calculations Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> - 2013-05-27 20:32 +0200
Re: Shortint calculations kvstegemann@web.de - 2013-05-27 11:46 -0700
Re: Shortint calculations Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> - 2013-05-27 23:40 +0200
Re: Shortint calculations "Wolfgang Riedmann" <wriedmann@gmail.com> - 2013-05-28 08:02 +0200
Re: Shortint calculations Mathias <mathias.hakansson@consultec.se> - 2013-05-27 22:39 -0700
Re: Shortint calculations Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> - 2013-05-28 09:01 +0200
Re: Shortint calculations kvstegemann@web.de - 2013-05-28 01:02 -0700
Re: Shortint calculations Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> - 2013-05-28 10:32 +0200
Re: Shortint calculations kvstegemann@web.de - 2013-05-28 01:46 -0700
Re: Shortint calculations Meinhard Schnoor-Matriciani <msm@appfact.de> - 2013-05-28 11:45 +0200
Re: Shortint calculations Mathias <mathias.hakansson@consultec.se> - 2013-05-28 23:45 -0700
Re: Shortint calculations "Er!k \\/!$$Er" <nospam@nospam.url> - 2013-05-29 16:57 +0200
Re: Shortint calculations dlzc <dlzc1@cox.net> - 2013-05-29 09:33 -0700
Re: Shortint calculations dlzc <dlzc1@cox.net> - 2013-05-28 07:15 -0700
Re: Shortint calculations Mathias <mathias.hakansson@consultec.se> - 2013-05-29 04:44 -0700
Re: Shortint calculations dlzc <dlzc1@cox.net> - 2013-05-29 07:25 -0700
Re: Shortint calculations "Jamal" <jamal@examples.net> - 2013-05-29 17:18 -0400
Re: Shortint calculations kvstegemann@web.de - 2013-05-30 01:47 -0700
Re: Shortint calculations "Jamal" <jamal@examples.net> - 2013-05-30 13:19 -0400
Re: Shortint calculations Meinhard Schnoor-Matriciani <msm@appfact.de> - 2013-05-30 22:05 +0200
Re: Shortint calculations kvstegemann@web.de - 2013-05-31 03:43 -0700
Page 1 of 2 [1] 2 Next page →
| From | kvstegemann@web.de |
|---|---|
| Date | 2013-05-27 08:53 -0700 |
| Subject | Shortint calculations |
| Message-ID | <aa22a440-8e92-444c-9538-3488ccce999d@googlegroups.com> |
Hi out there,
I'm getting strange results with simple calculations with shortints. Consider this mini-test-app:
FUNCTION Start()
LOCAL nA, nB, nC AS SHORTINT
nA := 748
nB := 22
nC := 35
IF nA > ( nB - nC )
? "748 is greater than (22 - 35)"
ELSE
? "748 is not greater than (22 - 35). Oops!"
ENDIF
_Wait("")
Try it and tell me what happens here. When the three variables are declared as longint, everything seems ok. But when they are shortints, the result is obviously wrong. It seems to me that the results here are well within the scope of a shortint, so what am I missing? (Using VO 2.8 Sp2)
Thanks for input
Kay-Viktor
[toc] | [next] | [standalone]
| From | Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> |
|---|---|
| Date | 2013-05-27 18:09 +0200 |
| Message-ID | <h717q8hp17ish4pm5nus3rmrojj97fhd4h@4ax.com> |
| In reply to | #5283 |
Kay,
strange indeed - i see it with Sp 4 but not with VN2...
Karl
>Hi out there,
>
>I'm getting strange results with simple calculations with shortints. Consider this mini-test-app:
>
>FUNCTION Start()
>
> LOCAL nA, nB, nC AS SHORTINT
>
> nA := 748
> nB := 22
> nC := 35
>
> IF nA > ( nB - nC )
> ? "748 is greater than (22 - 35)"
> ELSE
> ? "748 is not greater than (22 - 35). Oops!"
> ENDIF
>
> _Wait("")
>
>
>Try it and tell me what happens here. When the three variables are declared as longint, everything seems ok. But when they are shortints, the result is obviously wrong. It seems to me that the results here are well within the scope of a shortint, so what am I missing? (Using VO 2.8 Sp2)
>
>Thanks for input
>Kay-Viktor
[toc] | [prev] | [next] | [standalone]
| From | dlzc <dlzc1@cox.net> |
|---|---|
| Date | 2013-05-27 10:21 -0700 |
| Message-ID | <ca879809-f20c-4d98-a225-44d4e73ae01e@googlegroups.com> |
| In reply to | #5283 |
Dear kvste...: On Monday, May 27, 2013 8:53:43 AM UTC-7, kvste...@web.de wrote: ... > LOCAL nA, nB, nC AS SHORTINT > > nA := 748 > nB := 22 > nC := 35 > > IF nA > ( nB - nC ) > ? "748 is greater than (22 - 35)" > ELSE > ? "748 is not greater than (22 - 35). Oops!" > ENDIF ... > > When the three variables are declared as longint, > everything seems ok. But when they are shortints, > the result is obviously wrong. Are shortints signed? Can you print (nB - nC)? > It seems to me that the results here are well > within the scope of a shortint, so what am I missing? > (Using VO 2.8 Sp2) Shortint might be unsigned, so the amount that nC is greater than nB, is deducted from 65536. David A. Smith
[toc] | [prev] | [next] | [standalone]
| From | Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> |
|---|---|
| Date | 2013-05-27 20:32 +0200 |
| Message-ID | <lj97q8poflhnip8r9iefigh2oce3bhni35@4ax.com> |
| In reply to | #5285 |
>Are shortints signed? Can you print (nB - nC)? gives -13, as it should... Karl >> It seems to me that the results here are well >> within the scope of a shortint, so what am I missing? >> (Using VO 2.8 Sp2) > >Shortint might be unsigned, so the amount that nC is greater than nB, is deducted from 65536. > >David A. Smith
[toc] | [prev] | [next] | [standalone]
| From | kvstegemann@web.de |
|---|---|
| Date | 2013-05-27 11:46 -0700 |
| Message-ID | <fc9ab794-eb2e-462d-a633-8df7bfa03f26@googlegroups.com> |
| In reply to | #5285 |
> Are shortints signed? Can you print (nB - nC)? David, shortints are signed and should have no problems with negative values in this range. I've had enough headaches with word/dword values within calculations therefore I preferred shortints, but now this ... Kay-Viktor
[toc] | [prev] | [next] | [standalone]
| From | Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> |
|---|---|
| Date | 2013-05-27 23:40 +0200 |
| Message-ID | <kik7q8le7ja7i438je3bpuspmfn0jl7fra@4ax.com> |
| In reply to | #5287 |
Kay-Viktor, >values within calculations therefore I preferred shortints, but now this ... any reason to use shorts? Do you such number crunching that the size really matters vs "regular" ints? Not saying, that your results are pointing on some bug, which should be corrected, but in this case i think the workaround relatively easy ;-) Karl
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2013-05-28 08:02 +0200 |
| Message-ID | <b0ivk9Fn4c6U1@mid.individual.net> |
| In reply to | #5287 |
Hi Kay-Viktor, > shortints are signed and should have no problems with negative values > in this range. I've had enough headaches with word/dword values > within calculations therefore I preferred shortints, but now this ... on a 32 bit system it is better to user int and dword because they are 32 bit values. Shortint and word are 16 bit values and have a performance penalty because they need to be aligned to 32 bit. Wolfgang P.S. I think that VO behaves erratically in your sample --
[toc] | [prev] | [next] | [standalone]
| From | Mathias <mathias.hakansson@consultec.se> |
|---|---|
| Date | 2013-05-27 22:39 -0700 |
| Message-ID | <456106ce-3950-46bd-9800-de8543f5df72@googlegroups.com> |
| In reply to | #5283 |
This sample may be en explanation, but I still Think it's very confusing. It seems like if all the numbers are longints. But maybe only nb - nC is a longint and something goes wrong when comparing a shortint and a longint in nA > ( nB - nC )?
/Mathias
function Start()
local nA, nB, nC as shortint
nA := 748
nB := 22
nC := 35
? "Shortint?"
? UsualType(nB - nC) == shortint
? "Longint?"
? UsualType(nB - nC) == longint
? "Shortint?"
? UsualType(nA) == shortint
? "Longint?"
? UsualType(nA) == longint
? nB - nC
? nA
? nA > ( nB - nC )
? longint(nA) > ( nB - nC )
if longint(nA) > nB - nC
? "748 is greater than (22 - 35)"
else
? "748 is not greater than (22 - 35). Oops!"
endif
_Wait("")
return nil
Den måndagen den 27:e maj 2013 kl. 17:53:43 UTC+2 skrev kvste...@web.de:
> Hi out there,
>
>
>
> I'm getting strange results with simple calculations with shortints. Consider this mini-test-app:
>
>
>
> FUNCTION Start()
>
>
>
> LOCAL nA, nB, nC AS SHORTINT
>
>
>
> nA := 748
>
> nB := 22
>
> nC := 35
>
>
>
> IF nA > ( nB - nC )
>
> ? "748 is greater than (22 - 35)"
>
> ELSE
>
> ? "748 is not greater than (22 - 35). Oops!"
>
> ENDIF
>
>
>
> _Wait("")
>
>
>
>
>
> Try it and tell me what happens here. When the three variables are declared as longint, everything seems ok. But when they are shortints, the result is obviously wrong. It seems to me that the results here are well within the scope of a shortint, so what am I missing? (Using VO 2.8 Sp2)
>
>
>
> Thanks for input
>
> Kay-Viktor
[toc] | [prev] | [next] | [standalone]
| From | Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> |
|---|---|
| Date | 2013-05-28 09:01 +0200 |
| Message-ID | <lsk8q8tlk92eoqvu0pfkrqb44fc0spqkgp@4ax.com> |
| In reply to | #5289 |
Mathias & all,
just had a look, my compiler options has set (as per default)
"Overflow checking", so i'd expect a compiletime error at nA := 748,
not a "silent" cast. Stranger still, why, if it does the casts, the
compare goes wrong. Strangest, that the same code in VN2 gives the
correct compare, but also no warning at the assignment of nA...
Karl
>This sample may be en explanation, but I still Think it's very confusing. It seems like if all the numbers are longints. But maybe only nb - nC is a longint and something goes wrong when comparing a shortint and a longint in nA > ( nB - nC )?
>
>/Mathias
>
>function Start()
> local nA, nB, nC as shortint
>
> nA := 748
> nB := 22
> nC := 35
>
>
>
> ? "Shortint?"
> ? UsualType(nB - nC) == shortint
> ? "Longint?"
> ? UsualType(nB - nC) == longint
>
> ? "Shortint?"
> ? UsualType(nA) == shortint
> ? "Longint?"
> ? UsualType(nA) == longint
>
> ? nB - nC
> ? nA
> ? nA > ( nB - nC )
> ? longint(nA) > ( nB - nC )
>
> if longint(nA) > nB - nC
> ? "748 is greater than (22 - 35)"
> else
> ? "748 is not greater than (22 - 35). Oops!"
> endif
>
> _Wait("")
>
>
>return nil
>
>
>Den måndagen den 27:e maj 2013 kl. 17:53:43 UTC+2 skrev kvste...@web.de:
>> Hi out there,
>>
>>
>>
>> I'm getting strange results with simple calculations with shortints. Consider this mini-test-app:
>>
>>
>>
>> FUNCTION Start()
>>
>>
>>
>> LOCAL nA, nB, nC AS SHORTINT
>>
>>
>>
>> nA := 748
>>
>> nB := 22
>>
>> nC := 35
>>
>>
>>
>> IF nA > ( nB - nC )
>>
>> ? "748 is greater than (22 - 35)"
>>
>> ELSE
>>
>> ? "748 is not greater than (22 - 35). Oops!"
>>
>> ENDIF
>>
>>
>>
>> _Wait("")
>>
>>
>>
>>
>>
>> Try it and tell me what happens here. When the three variables are declared as longint, everything seems ok. But when they are shortints, the result is obviously wrong. It seems to me that the results here are well within the scope of a shortint, so what am I missing? (Using VO 2.8 Sp2)
>>
>>
>>
>> Thanks for input
>>
>> Kay-Viktor
[toc] | [prev] | [next] | [standalone]
| From | kvstegemann@web.de |
|---|---|
| Date | 2013-05-28 01:02 -0700 |
| Message-ID | <28c0ea56-652e-4746-b71c-c33c4a45199d@googlegroups.com> |
| In reply to | #5291 |
Karl, why should there be any sort of error at nA := 748 ? A shortint should be perfectly capable of holding a value like 748. The range of shortints is -32767 to +32768, correct me if I'm wrong. Therefore all the mentioned operations should work perfectly. To all: The original reason why I used shortints sometimes (in this case the whole thing is about window size calculations) was because some Windows API functions require shortint parameters. But I would never have suspected that shortint computations are broken in VO (after all those years ...). I will change them to longints and hope the headache goes away. Have a nice day Kay-Viktor
[toc] | [prev] | [next] | [standalone]
| From | Karl Faller <mail_withoutthat_@_drei-f_andthat_.de> |
|---|---|
| Date | 2013-05-28 10:32 +0200 |
| Message-ID | <kfq8q8tqv2ggo5gqsurp2qu3ncso0gqba4@4ax.com> |
| In reply to | #5292 |
Kay, >why should there be any sort of error at nA := 748 ? A shortint should be perfectly capable of holding a value like 748. The range of shortints is -32767 to +32768, correct me if I'm wrong. that was my thinking, too, but then i googled and found: * delphibasics.com says: "ShortInt type is the smallest form of signed integer, occupying 8 bits (1 byte) of storage. It supports only the integers from -128 to 127. " * wikipedia says: Short/short, Integer signed -32.768 32.767 * VO pre release manuals <g>, says 16bit int, as in Ansi C short Good, that i never used them... Karl
[toc] | [prev] | [next] | [standalone]
| From | kvstegemann@web.de |
|---|---|
| Date | 2013-05-28 01:46 -0700 |
| Message-ID | <d239ac8c-895b-491d-ae7c-07ac9b4aebd1@googlegroups.com> |
| In reply to | #5293 |
Am Dienstag, 28. Mai 2013 10:32:43 UTC+2 schrieb Karl Faller: > that was my thinking, too, but then i googled and found: > > * delphibasics.com says: "ShortInt type is the smallest form of > > signed integer, occupying 8 bits (1 byte) of storage. It supports only > > the integers from -128 to 127. " > > > > * wikipedia says: Short/short, Integer signed -32.768 32.767 > > > > * VO pre release manuals , says 16bit int, as in Ansi C short Hi Karl, VO shortints are 16 bit as stated in the manual, therefore there should be no problem storing the values. The bug must be in the operations somewhere. This is definitely a VO bug. Kay-Viktor
[toc] | [prev] | [next] | [standalone]
| From | Meinhard Schnoor-Matriciani <msm@appfact.de> |
|---|---|
| Date | 2013-05-28 11:45 +0200 |
| Message-ID | <51a47d2d$0$6643$3ca0ca56@newsspool2.vodafone-ip.de> |
| In reply to | #5289 |
Mathias,
this approach must lead to confusions, because UsualType would never
return something like Shortint ( see documentation ).
I am going to have a look at this.
Regards
Meinhard
Am 28.05.2013 07:39, schrieb Mathias:
> This sample may be en explanation, but I still Think it's very confusing. It seems like if all the numbers are longints. But maybe only nb - nC is a longint and something goes wrong when comparing a shortint and a longint in nA > ( nB - nC )?
>
> /Mathias
>
> function Start()
> local nA, nB, nC as shortint
>
> nA := 748
> nB := 22
> nC := 35
>
>
>
> ? "Shortint?"
> ? UsualType(nB - nC) == shortint
> ? "Longint?"
> ? UsualType(nB - nC) == longint
>
> ? "Shortint?"
> ? UsualType(nA) == shortint
> ? "Longint?"
> ? UsualType(nA) == longint
>
> ? nB - nC
> ? nA
> ? nA > ( nB - nC )
> ? longint(nA) > ( nB - nC )
>
> if longint(nA) > nB - nC
> ? "748 is greater than (22 - 35)"
> else
> ? "748 is not greater than (22 - 35). Oops!"
> endif
>
> _Wait("")
>
>
> return nil
>
>
> Den måndagen den 27:e maj 2013 kl. 17:53:43 UTC+2 skrev kvste...@web.de:
>> Hi out there,
>>
>>
>>
>> I'm getting strange results with simple calculations with shortints. Consider this mini-test-app:
>>
>>
>>
>> FUNCTION Start()
>>
>>
>>
>> LOCAL nA, nB, nC AS SHORTINT
>>
>>
>>
>> nA := 748
>>
>> nB := 22
>>
>> nC := 35
>>
>>
>>
>> IF nA > ( nB - nC )
>>
>> ? "748 is greater than (22 - 35)"
>>
>> ELSE
>>
>> ? "748 is not greater than (22 - 35). Oops!"
>>
>> ENDIF
>>
>>
>>
>> _Wait("")
>>
>>
>>
>>
>>
>> Try it and tell me what happens here. When the three variables are declared as longint, everything seems ok. But when they are shortints, the result is obviously wrong. It seems to me that the results here are well within the scope of a shortint, so what am I missing? (Using VO 2.8 Sp2)
>>
>>
>>
>> Thanks for input
>>
>> Kay-Viktor
>
--
Meinhard Schnoor-Matriciani
Grafx Development Team
[toc] | [prev] | [next] | [standalone]
| From | Mathias <mathias.hakansson@consultec.se> |
|---|---|
| Date | 2013-05-28 23:45 -0700 |
| Message-ID | <018d375d-3c3f-4ba3-ab4f-a5075a8f4072@googlegroups.com> |
| In reply to | #5295 |
Hi Meinard,
I suspected that usuals don't carry shortints. However the whole thing is very confusing and it gets even more confusing if I modify the testprogram like below. It seems like it works if I calculate the subtraction before comparing.
function Start()
local nA, nB, nC, nD as shortint
nA := 748
nB := 22
nC := 35
nD := nB - nC
? nB - nC // -13
? nD // -13
? nA // 748
? nA > nB - nC // .F.
? nA > nD // .T.
? longint(nA) > ( nB - nC ) // .T.
if longint(nA) > nB - nC
? "748 is greater than (22 - 35)"
else
? "748 is not greater than (22 - 35). Oops!"
endif
_Wait("")
return nil
Den tisdagen den 28:e maj 2013 kl. 11:45:31 UTC+2 skrev Meinhard Schnoor-Matriciani:
> Mathias,
>
>
>
> this approach must lead to confusions, because UsualType would never
>
> return something like Shortint ( see documentation ).
>
>
>
> I am going to have a look at this.
>
>
>
> Regards
>
> Meinhard
>
>
>
> Am 28.05.2013 07:39, schrieb Mathias:
>
> > This sample may be en explanation, but I still Think it's very confusing. It seems like if all the numbers are longints. But maybe only nb - nC is a longint and something goes wrong when comparing a shortint and a longint in nA > ( nB - nC )?
>
> >
>
> > /Mathias
>
> >
>
> > function Start()
>
> > local nA, nB, nC as shortint
>
> >
>
> > nA := 748
>
> > nB := 22
>
> > nC := 35
>
> >
>
> >
>
> >
>
> > ? "Shortint?"
>
> > ? UsualType(nB - nC) == shortint
>
> > ? "Longint?"
>
> > ? UsualType(nB - nC) == longint
>
> >
>
> > ? "Shortint?"
>
> > ? UsualType(nA) == shortint
>
> > ? "Longint?"
>
> > ? UsualType(nA) == longint
>
> >
>
> > ? nB - nC
>
> > ? nA
>
> > ? nA > ( nB - nC )
>
> > ? longint(nA) > ( nB - nC )
>
> >
>
> > if longint(nA) > nB - nC
>
> > ? "748 is greater than (22 - 35)"
>
> > else
>
> > ? "748 is not greater than (22 - 35). Oops!"
>
> > endif
>
> >
>
> > _Wait("")
>
> >
>
> >
>
> > return nil
>
> >
>
> >
>
> > Den m�ndagen den 27:e maj 2013 kl. 17:53:43 UTC+2 skrev kvste...@web.de:
>
> >> Hi out there,
>
> >>
>
> >>
>
> >>
>
> >> I'm getting strange results with simple calculations with shortints. Consider this mini-test-app:
>
> >>
>
> >>
>
> >>
>
> >> FUNCTION Start()
>
> >>
>
> >>
>
> >>
>
> >> LOCAL nA, nB, nC AS SHORTINT
>
> >>
>
> >>
>
> >>
>
> >> nA := 748
>
> >>
>
> >> nB := 22
>
> >>
>
> >> nC := 35
>
> >>
>
> >>
>
> >>
>
> >> IF nA > ( nB - nC )
>
> >>
>
> >> ? "748 is greater than (22 - 35)"
>
> >>
>
> >> ELSE
>
> >>
>
> >> ? "748 is not greater than (22 - 35). Oops!"
>
> >>
>
> >> ENDIF
>
> >>
>
> >>
>
> >>
>
> >> _Wait("")
>
> >>
>
> >>
>
> >>
>
> >>
>
> >>
>
> >> Try it and tell me what happens here. When the three variables are declared as longint, everything seems ok. But when they are shortints, the result is obviously wrong. It seems to me that the results here are well within the scope of a shortint, so what am I missing? (Using VO 2.8 Sp2)
>
> >>
>
> >>
>
> >>
>
> >> Thanks for input
>
> >>
>
> >> Kay-Viktor
>
> >
>
>
>
>
>
> --
>
> Meinhard Schnoor-Matriciani
>
> Grafx Development Team
[toc] | [prev] | [next] | [standalone]
| From | "Er!k \\/!$$Er" <nospam@nospam.url> |
|---|---|
| Date | 2013-05-29 16:57 +0200 |
| Message-ID | <ko5503$2lr5$1@adenine.netfront.net> |
| In reply to | #5298 |
Mathias,
I have tried this code on VO 2.6, VO 2.7 build 2773 and VO 2.8 build 2837
and it works fine here.
Erik
-13
-13
748
.F.
.T.
.T.
748 is greater than (22 - 35)
"Mathias" schreef in bericht
news:018d375d-3c3f-4ba3-ab4f-a5075a8f4072@googlegroups.com...
Hi Meinard,
I suspected that usuals don't carry shortints. However the whole thing is
very confusing and it gets even more confusing if I modify the testprogram
like below. It seems like it works if I calculate the subtraction before
comparing.
function Start()
local nA, nB, nC, nD as shortint
nA := 748
nB := 22
nC := 35
nD := nB - nC
? nB - nC // -13
? nD // -13
? nA // 748
? nA > nB - nC // .F.
? nA > nD // .T.
? longint(nA) > ( nB - nC ) // .T.
if longint(nA) > nB - nC
? "748 is greater than (22 - 35)"
else
? "748 is not greater than (22 - 35). Oops!"
endif
_Wait("")
return nil
Den tisdagen den 28:e maj 2013 kl. 11:45:31 UTC+2 skrev Meinhard
Schnoor-Matriciani:
> Mathias,
>
>
>
> this approach must lead to confusions, because UsualType would never
>
> return something like Shortint ( see documentation ).
>
>
>
> I am going to have a look at this.
>
>
>
> Regards
>
> Meinhard
>
>
>
> Am 28.05.2013 07:39, schrieb Mathias:
>
> > This sample may be en explanation, but I still Think it's very
> > confusing. It seems like if all the numbers are longints. But maybe only
> > nb - nC is a longint and something goes wrong when comparing a shortint
> > and a longint in nA > ( nB - nC )?
>
> >
>
> > /Mathias
>
> >
>
> > function Start()
>
> > local nA, nB, nC as shortint
>
> >
>
> > nA := 748
>
> > nB := 22
>
> > nC := 35
>
> >
>
> >
>
> >
>
> > ? "Shortint?"
>
> > ? UsualType(nB - nC) == shortint
>
> > ? "Longint?"
>
> > ? UsualType(nB - nC) == longint
>
> >
>
> > ? "Shortint?"
>
> > ? UsualType(nA) == shortint
>
> > ? "Longint?"
>
> > ? UsualType(nA) == longint
>
> >
>
> > ? nB - nC
>
> > ? nA
>
> > ? nA > ( nB - nC )
>
> > ? longint(nA) > ( nB - nC )
>
> >
>
> > if longint(nA) > nB - nC
>
> > ? "748 is greater than (22 - 35)"
>
> > else
>
> > ? "748 is not greater than (22 - 35). Oops!"
>
> > endif
>
> >
>
> > _Wait("")
>
> >
>
> >
>
> > return nil
>
> >
>
> >
>
> > Den m�ndagen den 27:e maj 2013 kl. 17:53:43 UTC+2 skrev
> > kvste...@web.de:
>
> >> Hi out there,
>
> >>
>
> >>
>
> >>
>
> >> I'm getting strange results with simple calculations with shortints.
> >> Consider this mini-test-app:
>
> >>
>
> >>
>
> >>
>
> >> FUNCTION Start()
>
> >>
>
> >>
>
> >>
>
> >> LOCAL nA, nB, nC AS SHORTINT
>
> >>
>
> >>
>
> >>
>
> >> nA := 748
>
> >>
>
> >> nB := 22
>
> >>
>
> >> nC := 35
>
> >>
>
> >>
>
> >>
>
> >> IF nA > ( nB - nC )
>
> >>
>
> >> ? "748 is greater than (22 - 35)"
>
> >>
>
> >> ELSE
>
> >>
>
> >> ? "748 is not greater than (22 - 35). Oops!"
>
> >>
>
> >> ENDIF
>
> >>
>
> >>
>
> >>
>
> >> _Wait("")
>
> >>
>
> >>
>
> >>
>
> >>
>
> >>
>
> >> Try it and tell me what happens here. When the three variables are
> >> declared as longint, everything seems ok. But when they are shortints,
> >> the result is obviously wrong. It seems to me that the results here are
> >> well within the scope of a shortint, so what am I missing? (Using VO
> >> 2.8 Sp2)
>
> >>
>
> >>
>
> >>
>
> >> Thanks for input
>
> >>
>
> >> Kay-Viktor
>
> >
>
>
>
>
>
> --
>
> Meinhard Schnoor-Matriciani
>
> Grafx Development Team
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | dlzc <dlzc1@cox.net> |
|---|---|
| Date | 2013-05-29 09:33 -0700 |
| Message-ID | <18f12c97-3ae8-438a-b7cd-9483a6867afa@googlegroups.com> |
| In reply to | #5303 |
Dear Er!k /!$$Er:
On Wednesday, May 29, 2013 7:57:06 AM UTC-7, Er!k /!$$Er wrote:
> Mathias,
>
> I have tried this code on VO 2.6, VO 2.7 build 2773
> and VO 2.8 build 2837 and it works fine here.
>
>
> -13
> -13
> 748
> .F.
This above says 748 is not greater than -13. Do you want to revise your "fine"?
> .T.
> .T.
> 748 is greater than (22 - 35)
...
> function Start()
>
> local nA, nB, nC, nD as shortint
>
> nA := 748
> nB := 22
> nC := 35
>
> nD := nB - nC
>
> ? nB - nC // -13
> ? nD // -13
> ? nA // 748
> ? nA > nB - nC // .F.
> ? nA > nD // .T.
> ? longint(nA) > ( nB - nC ) // .T.
>
> if longint(nA) > nB - nC
> ? "748 is greater than (22 - 35)"
> else
> ? "748 is not greater than (22 - 35). Oops!"
> endif
>
> _Wait("")
>
> return nil
Erik's results say that this has been broken for a long time. And it looks like a negative longint result is downcoverted incorrectly to a shortint.
I wonder what:
? shortint( longint( -13 )) // looks like?
David A. Smith
[toc] | [prev] | [next] | [standalone]
| From | dlzc <dlzc1@cox.net> |
|---|---|
| Date | 2013-05-28 07:15 -0700 |
| Message-ID | <0d515ec5-a6d5-4e1f-9ea8-13c5128f0798@googlegroups.com> |
| In reply to | #5283 |
Dear kvste...: On Monday, May 27, 2013 8:53:43 AM UTC-7, kvste...@web.de wrote: ... > LOCAL nA, nB, nC AS SHORTINT > > nA := 748 > nB := 22 > nC := 35 > > IF nA > ( nB - nC ) Here is the problem, the result of subtraction is NOT a shortint. It is (probably) a long integer. When compared to the shortint nA, the result of subtraction may be being truncated, rather than the result being demoted to a shortint, or nA being promoted to a long int. > ? "748 is greater than (22 - 35)" > ELSE > ? "748 is not greater than (22 - 35). Oops!" > ENDIF It sure looks like a bug to me. David A. Smith
[toc] | [prev] | [next] | [standalone]
| From | Mathias <mathias.hakansson@consultec.se> |
|---|---|
| Date | 2013-05-29 04:44 -0700 |
| Message-ID | <418e57c0-80db-420d-a98d-c3da4c19c2d9@googlegroups.com> |
| In reply to | #5297 |
Hi David, no it's more complicated than this... ? shortint(nA) > nD // .T. No surprise, as nA > nD also was true. nA is allready a shortint so this is expected. ? shortint(nA) > nB - nC // .F. Expected... ? nA > shortint(nD) // .F. What? nD is a shortint. Converting to a shortint should have no effect as nD allready is a shortint. ? shortint(nA) > shortint(nD) // .F. Strange ideed... /MathiasH Den tisdagen den 28:e maj 2013 kl. 16:15:04 UTC+2 skrev dlzc: > Dear kvste...: > > > > On Monday, May 27, 2013 8:53:43 AM UTC-7, kvste...@web.de wrote: > > ... > > > LOCAL nA, nB, nC AS SHORTINT > > > > > > nA := 748 > > > nB := 22 > > > nC := 35 > > > > > > IF nA > ( nB - nC ) > > > > Here is the problem, the result of subtraction is NOT a shortint. It is (probably) a long integer. When compared to the shortint nA, the result of subtraction may be being truncated, rather than the result being demoted to a shortint, or nA being promoted to a long int. > > > > > ? "748 is greater than (22 - 35)" > > > ELSE > > > ? "748 is not greater than (22 - 35). Oops!" > > > ENDIF > > > > It sure looks like a bug to me. > > > > David A. Smith
[toc] | [prev] | [next] | [standalone]
| From | dlzc <dlzc1@cox.net> |
|---|---|
| Date | 2013-05-29 07:25 -0700 |
| Message-ID | <6e14b938-f3b6-46ac-b90e-5e051460a891@googlegroups.com> |
| In reply to | #5301 |
Dear Mathias: On Wednesday, May 29, 2013 4:44:22 AM UTC-7, Mathias wrote: ... > no it's more complicated than this... ... Really not, but you did find the exact cause, I think. > ? shortint(nA) > nB - nC // .F. > > Expected... ... since nA was already a shortint, and (nB - nC) is a long int (or worse) > ? nA > shortint(nD) // .F. > > What? nD is a shortint. Converting to a shortint > should have no effect as nD allready is a shortint. The problem is sign extending in shortint conversion. Apparently conversion occurs even if the data type is already shortint. > ? shortint(nA) > shortint(nD) // .F. > > Strange ideed... The conversion fails miserably on negatives. David A. Smith
[toc] | [prev] | [next] | [standalone]
| From | "Jamal" <jamal@examples.net> |
|---|---|
| Date | 2013-05-29 17:18 -0400 |
| Message-ID | <ko5raf$hba$1@speranza.aioe.org> |
| In reply to | #5283 |
Hi Kay-Victor,
It seems to be a bug the > operator internal handling of Short INT.
If you reverse the test to use the < (less than operator):
IF ( nB - nC ) < nA
? "(22 - 35) is less than 748"
ENDIF
It works as expected. So try putting the complex expression part in left
hand of the comparison.
Jamal
wrote in message
news:aa22a440-8e92-444c-9538-3488ccce999d@googlegroups.com...
Hi out there,
I'm getting strange results with simple calculations with shortints.
Consider this mini-test-app:
FUNCTION Start()
LOCAL nA, nB, nC AS SHORTINT
nA := 748
nB := 22
nC := 35
IF nA > ( nB - nC )
? "748 is greater than (22 - 35)"
ELSE
? "748 is not greater than (22 - 35). Oops!"
ENDIF
_Wait("")
Try it and tell me what happens here. When the three variables are declared
as longint, everything seems ok. But when they are shortints, the result is
obviously wrong. It seems to me that the results here are well within the
scope of a shortint, so what am I missing? (Using VO 2.8 Sp2)
Thanks for input
Kay-Viktor
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web