Recent

Author Topic: Error in conditionals - Lazarus 1.8.0 Win32  (Read 10442 times)

PsaCrypt

  • New Member
  • *
  • Posts: 21
Error in conditionals - Lazarus 1.8.0 Win32
« on: February 16, 2018, 10:36:37 pm »
Hello to all,

converting my own functions library to Lazarus 1.8.0 in Win32 I found a little but many important error.  This is the function:

Code: Pascal  [Select][+][-]
  1. Function IsRange(nIn, nMin, nMax: Extended): Boolean;
  2. Begin
  3.  
  4.  Result := True;
  5.  If (nIn < nMin) Or (nIn > nMax) Then Result := False;
  6.  
  7. End;
  8.  

Evaluating  IsRange(27, 0, 9) returns True, and must return False.

How to solve this problem?

:-(


taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #1 on: February 16, 2018, 10:53:00 pm »
are you sure? see attachment.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #2 on: February 16, 2018, 11:13:56 pm »
Works fine for me with 1.8.0 win32
The only true wisdom is knowing you know nothing

PsaCrypt

  • New Member
  • *
  • Posts: 21
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #3 on: February 16, 2018, 11:53:54 pm »
Sure.  Is in Win7 x32.  I use this function to define range limits and assign right ASCII values into my own base2 to base252 converting functions.  Using base36 27 must return R, but it returns 8 (normal range digits 0 to 9).  Bad assignation.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #4 on: February 17, 2018, 03:22:55 pm »
I have no idea what you are talking about, it surely does not relate with the material you posted here..

btw, you can shorten that function a little;

Function IsRange(nIn, nMin, nMax: Extended): Boolean;
Begin
 Result := Not ( (nIn < nMin) Or (nIn > nMax));
End;
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #5 on: February 17, 2018, 03:32:42 pm »
I have no idea what you are talking about, it surely does not relate with the material you posted here..

btw, you can shorten that function a little;

Function IsRange(nIn, nMin, nMax: Extended): Boolean;
Begin
 Result := Not ( (nIn < nMin) Or (nIn > nMax));
End;
Moreover, using logical transformations, this is equivalent to
Code: [Select]
  Result := (nIn >= nMin) and (nIn <= nMax);
and... we get code from Math.InRange  :D

PsaCrypt

  • New Member
  • *
  • Posts: 21
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #6 on: February 17, 2018, 06:54:15 pm »
Jamie, the function is called from another function who haves data converting ascii tables.  but think in this case i can not try alternatives like do case.

ASerge, i tryed before <= & >= operators.  the problem is processing these operators with if condition.  still i don't know math.inrange, i will test it.

thank you.  :-)

Bart

  • Hero Member
  • *****
  • Posts: 5274
    • Bart en Mariska's Webstek
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #7 on: February 17, 2018, 07:04:36 pm »
You really think that "<" and ">" operators give wrong results in a compiler that has been around for so many years?
And nobody else but you would have noticed?
Really?
Really?
Really?
Really?
Really?
Really?
Really?
Really?

Bart

PsaCrypt

  • New Member
  • *
  • Posts: 21
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #8 on: February 17, 2018, 08:11:51 pm »
ASerge & Bart, yes I use these operators for many years in other compilers without any issue.  The case is that function gives wrong result, and tracing source code fails at isrange() processing.  Ghosts?  I don't believe.  I used my base2 to base252 converter since I made it on 2004 year.  It runs fine. 

Trying Not(...) from ASerge function runs fine separately, and I suppossed original isrange() function too.

Then I must supposse that error was when concatenating if...then...else to process all values to convert to right value, like this:

if isrange(...) then ... else if isrange(...) then ... else if isrange(...) then ... ;

enclosed within another

if ... then begin ... end;

structure.

It fails and I don't know why.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #9 on: February 17, 2018, 08:42:08 pm »
ASerge & Bart, yes I use these operators for many years in other compilers without any issue.  The case is that function gives wrong result, and tracing source code fails at isrange() processing.  Ghosts?  I don't believe.  I used my base2 to base252 converter since I made it on 2004 year.  It runs fine. 

Trying Not(...) from ASerge function runs fine separately, and I suppossed original isrange() function too.
ASerge said that your code can be simplified to
Code: Pascal  [Select][+][-]
  1. Function IsRange(nIn, nMin, nMax: Extended): Boolean;
  2. Begin
  3.  Result := (nIn >= nMin) and (nIn <= nMax);
  4. End;
  5.  
which is the same as the code in the function InRange in the math unit, you could add a inline specifier as well to make things run faster.

Then I must supposse that error was when concatenating if...then...else to process all values to convert to right value, like this:

if isrange(...) then ... else if isrange(...) then ... else if isrange(...) then ... ;

enclosed within another

if ... then begin ... end;

structure.

It fails and I don't know why.
you can "suppose" all you want but if you want our help to find the problem I would suggest posting either the code or a sample of the code that produces the error, along with test data aka input values and expected results. Anything less and we end up as blind people throwing stones around to hit a bell without breaking every fragile object in the room, with you guiding us where to throw the stones. Not a pleasant endeavor for all the parties involved.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Bart

  • Hero Member
  • *****
  • Posts: 5274
    • Bart en Mariska's Webstek
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #10 on: February 17, 2018, 11:36:30 pm »
It fails and I don't know why.

Without actual code (and data) it is impossible to tell (in the absent of a crystal ball).

Belive it or not, we really are prepared to help you find the problem.

Bart

PsaCrypt

  • New Member
  • *
  • Posts: 21
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #11 on: February 18, 2018, 12:07:37 am »
I don't have internet connection from computer, and VBox host network adapter does not allow me transfer files to send from mobile phone.  These functions of my library are free software.  You can download sample sourcecode from GitHub (Secured-Hash, Harbour Compiler) and translate to Lazarus.

Bart

  • Hero Member
  • *****
  • Posts: 5274
    • Bart en Mariska's Webstek
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #12 on: February 18, 2018, 12:49:58 am »
OK, I give up then.

Bart

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #13 on: February 18, 2018, 01:53:41 am »
Hello PsaCrypt, I don't mean not believe the error you found. But often some users said they found that the compiler not working correctly, after some inspections it ended as those were the programmer own faults.

Bugs can hide in anywhere of the code, you just gave us the function that you think causing error. But none of us can reproduce the issue. Please find a way to send us the compilable/runable source code.

If for some reasons you're not willing to publish your project, you can write a demo project that showing the issue.

PsaCrypt

  • New Member
  • *
  • Posts: 21
Re: Error in conditionals - Lazarus 1.8.0 Win32
« Reply #14 on: February 18, 2018, 01:59:46 pm »
Sorry for later because need to be in WiFi bar to send source code or files.  Now at one.  The function returning wrong result is next:

Code: Pascal  [Select][+][-]
  1. Function BaseXTable(xNum: Variant; nBase: Extended; lSwStr: Boolean): Variant;  
  2. Var
  3.  xTmp: Variant;
  4.  nTmp: LongInt;
  5.  lError: Boolean;
  6.  
  7. Begin
  8.  
  9.  nTmp := 0;
  10.  lError := False;
  11.  
  12. If (IsRange(nBase, 2, 252) <> False) Then Begin
  13. If (lSwStr <> True) Then Begin
  14.  If (IsRange(xNum, 0, 9) <> False) Then xTmp := Char(xNum + 48) Else
  15.  If (IsRange(xNum, 10, 35) <> False) Then xTmp := Char(xNum + 55) Else
  16.  If (IsRange(xNum, 36, 61) <> False) Then xTmp := Char(xNum + 61) Else
  17.  If (xNum = 62) Then xTmp := #043 Else
  18.  If (xNum = 63) Then xTmp := #047 Else
  19.  If (IsRange(xNum, 64, 196) <> False) Then xTmp := Char(xNum + 59) Else
  20.  If (IsRange(xNum, 197, 202) <> False) Then xTmp := Char(xNum - 106) Else
  21.  If (IsRange(xNum, 203, 209) <> False) Then xTmp := Char(xNum - 145) Else
  22.  If (xNum = 210) Then xTmp := #044 Else
  23.  If (IsRange(xNum, 211, 220) <> False) Then xTmp := Char(xNum - 178) Else
  24.  If (IsRange(xNum, 221, 238) <> False) Then xTmp := Char(xNum - 207) Else
  25.  If (IsRange(xNum, 239, 251) <> False) Then xTmp := Char(xNum - 238);
  26.  
  27. End Else If (lSwStr <> False) Then Begin
  28.  cTmp := xNum.Trim;
  29.  If (nBase <= 36) Then cTmp := UpperCase(cTmp);
  30.  nTmp := Byte(cTmp[1]);
  31.  
  32.  If (IsRange(nTmp, 48, 57) <> False) Then xTmp := (nTmp - 48) Else
  33.  If (IsRange(nTmp, 65, 90) <> False) Then xTmp := (nTmp - 55) Else
  34.  If (IsRange(nTmp, 97, 122) <> False) Then xTmp := (nTmp - 61) Else
  35.  If (nTmp = 43) Then xTmp := (62) Else
  36.  If (nTmp = 47) Then xTmp := (63) Else
  37.  If (IsRange(nTmp, 123, 255) <> False) Then xTmp := (nTmp - 59) Else
  38.  If (IsRange(nTmp, 91, 96) <> False) Then xTmp := (nTmp + 106) Else
  39.  If (IsRange(nTmp, 58, 64) <> False) Then xTmp := (nTmp + 145) Else
  40.  If (nTmp = 44) Then xTmp := (210) Else
  41.  If (IsRange(nTmp, 33, 42) <> False) Then xTmp := (nTmp + 178) Else
  42.  If (IsRange(nTmp, 14, 31) <> False) Then xTmp := (nTmp + 207) Else
  43.  If (IsRange(nTmp, 1, 13) <> False) Then xTmp := (nTmp + 238);
  44.  If (xTmp >= nBase) Then lError := True;
  45. End;
  46. End;
  47.  
  48.  If (lError <> True) Then Result := xTmp Else Result := '*** Error ***';
  49.  
  50. End;
  51.  

With basextable(27, 36, false) must return value at ...

IsRange(xNum, 10, 35)   =>   xTmp := Char(xNum + 55)

But returns wrong value at ...

IsRange(xNum, 0, 9)   =>    xTmp := Char(xNum + 48)

This is the wrong result returned.

:-(

 

TinyPortal © 2005-2018