Skip to main content

Ok,  chasing my tail for a bit on this one.  

RC = 5061.10

LL = 5061.1

IF LL = RC THEN

CRT "WHY, THEY ARE NOT EQUAL"

END

They don't match!  why does it drop the 0 on the compare?  What is the correct way to fix.



------------------------------
Craig Curtis
System Programmer
Sevier Valley School District
Richfield UT US
------------------------------

Ok,  chasing my tail for a bit on this one.  

RC = 5061.10

LL = 5061.1

IF LL = RC THEN

CRT "WHY, THEY ARE NOT EQUAL"

END

They don't match!  why does it drop the 0 on the compare?  What is the correct way to fix.



------------------------------
Craig Curtis
System Programmer
Sevier Valley School District
Richfield UT US
------------------------------

Try multiplying each by 1.



------------------------------
Marcus Rhodes
marcus1@thinqware.com
------------------------------

Try multiplying each by 1.



------------------------------
Marcus Rhodes
marcus1@thinqware.com
------------------------------

Nope.  same outcome.

I can do crazy stuff like

RC = '"':RC:'"'

LL = '"':LL:'"'

and then it will work.  Is there iconv to convert to string?



------------------------------
Craig Curtis
System Programmer
Sevier Valley School District
Richfield UT US
------------------------------

Try multiplying each by 1.



------------------------------
Marcus Rhodes
marcus1@thinqware.com
------------------------------

that is because of the PRECISION statement

i like to make like this

      RC = OCONV("5061.10","MCNA")
      LL = OCONV("5061.1","MCNA")
      IF LL = RC THEN
         CRT "WHY, THEY ARE NOT EQUAL"
      END ELSE
         CRT "EAHHHH"
      END




------------------------------
Alberto Leal
System Analyst
Millano Distribuidora de Auto Pecas Ltda
Varzea Grande MT BR
------------------------------

that is because of the PRECISION statement

i like to make like this

      RC = OCONV("5061.10","MCNA")
      LL = OCONV("5061.1","MCNA")
      IF LL = RC THEN
         CRT "WHY, THEY ARE NOT EQUAL"
      END ELSE
         CRT "EAHHHH"
      END




------------------------------
Alberto Leal
System Analyst
Millano Distribuidora de Auto Pecas Ltda
Varzea Grande MT BR
------------------------------

I like that one.   Was looking at the conversion codes but.......

Thanks



------------------------------
Craig Curtis
System Programmer
Sevier Valley School District
Richfield UT US
------------------------------

that is because of the PRECISION statement

i like to make like this

      RC = OCONV("5061.10","MCNA")
      LL = OCONV("5061.1","MCNA")
      IF LL = RC THEN
         CRT "WHY, THEY ARE NOT EQUAL"
      END ELSE
         CRT "EAHHHH"
      END




------------------------------
Alberto Leal
System Analyst
Millano Distribuidora de Auto Pecas Ltda
Varzea Grande MT BR
------------------------------

IF "X":LL = "X":RC THEN ...



------------------------------
Stefano Maran
Senior programmer
GTN SpA
Tavagnacco IT
------------------------------

Nope.  same outcome.

I can do crazy stuff like

RC = '"':RC:'"'

LL = '"':LL:'"'

and then it will work.  Is there iconv to convert to string?



------------------------------
Craig Curtis
System Programmer
Sevier Valley School District
Richfield UT US
------------------------------

Hi there,

You have just answered your own question: Why don't they match

Match/= is matching, and 1.1 is a different FORMAT to 1.10

whereas "abc&" is the same format as "abc&"

Multiplying both 'numbers' will result in 2 'numbers in the same format as set in you SYSTEM command set e.g. NNN.NN (2 decimal places), and shown thus 1.10 1.10 for matching, but displaying as 1.1

We all have to go back to BASIC to remember why things do work well, without anything added to our wonderful languages to make up for the failings in other languages e.g. C, C++_, etc.

Can't beat PICK System aka Multivalue for being a fantastic language (as well as the accessing it's incredible mv (MMV/SV) database = unlimited dimensional data).  

Merry



------------------------------
Merry Player
Pick Multivalue Person since CMC (1978) /Microdata/McD/Northgate and onwards Reality/Zebra/Mentor/Ultimate/Universe/Unidata into Pick, Pick AP, and so on up until 2021 on mvBase/D3 - so far ....
Isle of Wight England
------------------------------

Ok,  chasing my tail for a bit on this one.  

RC = 5061.10

LL = 5061.1

IF LL = RC THEN

CRT "WHY, THEY ARE NOT EQUAL"

END

They don't match!  why does it drop the 0 on the compare?  What is the correct way to fix.



------------------------------
Craig Curtis
System Programmer
Sevier Valley School District
Richfield UT US
------------------------------

Hi Craig,

This peaked my interest so I did a bit of testing.

Unlike other languages, PICK Basic does not allow you to "type" a variable. No declaring that a variable is integer, single precision, etc.

In code if you assign a number to a variable the variable type becomes a generic "numeric". It can be an integer or a single precision number ( I don't believe that they can be double precision). The default precision for numbers is 4 with a maximum of 9.

So at the time of assignment the trailing unnecessary zero is stripped off.

At that point, in your example, RC will always be equal to LL.

It turns out that if you use two INPUT statements to assign values to RC and LL like:

INPUT RC

INPUT LL

and then compare them where one has the trailing zero and the other does not, PICK assigns the values as numbers and sees them as the same.

When PICK reads values from a file, it seems that all the values are read into the variable as "strings".

Try the following:

Create a record (VALUES for this example) in a file (TEST for this example) where the data looks like this:

0001 5601.10
0002 5601.1

Try this code:

OPEN '{filename}' TO TST ELSE STOP
READ REC FROM TST, '{record id}' ELSE STOP

CRT
CRT


! Output the "raw" values to the screen.
! Both will be as "entered" in the "VALUES" record.
! Assigned as strings in the read.
   CRT 'REC< 1 > : ' : REC< 1 >'L#10' : 'Length: ' : LEN( REC< 1 > )
   CRT 'REC< 2 > : ' : REC< 2 >'L#10' : 'Length: ' : LEN( REC< 2 > )
   CRT '  Test values and Lengths: ' : ( REC< 1 > EQ REC< 2 > AND LEN( REC< 1 > ) EQ LEN( REC< 2 > ) )
   CRT '  Test prepended string:   ' : ( 'A' : REC< 1 > EQ 'A' : REC< 2 > )
   CRT '  Test multiplying:         ' : (  REC< 1 >*1 EQ REC< 2 >*1 ) : '  forces numeric comparison'
   CRT '  Test just values:        ' : ( REC< 1 > EQ REC< 2 > ) : '  it seems this comparison converts strings to numbers.'
   CRT

! Create your two variables
   RC = REC< 1 >
   LL = REC< 2 >

! Output the assigned values to the screen.
! Both will be as "entered" in the "VALUES" record.
! Still strings.
   CRT 'RC: ' : RC'L#10' : 'Length: ' : LEN( RC )
   CRT 'LL: ' : LL'L#10' : 'Length: ' : LEN( LL )
   CRT '  Test values and Lengths: ' : ( RC EQ LL AND LEN( RC ) EQ LEN( LL ) )
   CRT '  Test prepended string:   ' : ( 'A' : RC EQ 'A' : LL )
   CRT '  Test multiplying:        ' : ( RC*1 EQ LL*1 ) : '  forces numeric comparison'
   CRT '  Test just values:        ' : ( RC EQ LL ) : '  it seems this comparison converts strings to numbers.'
   CRT

! Force variables to numeric types.
   RC = RC * 1
   LL = LL * 1

! Output the numeric values to the screen.
! Both will now be true numbers.
   CRT 'Number RC: ' : RC'L#10' : 'Length: ' : LEN( RC )
   CRT 'Number LL: ' : LL'L#10' : 'Length: ' : LEN( LL )
   CRT '  Test values and Lengths: ' : ( RC EQ LL AND LEN( RC ) EQ LEN( LL ) )
   CRT '  Test prepended string:   ' : ( 'A' : RC EQ 'A' : LL )
   CRT '  Test multiplying         ' : ( RC*1 EQ LL*1 ) : '  forces numeric comparison'
   CRT '  Test just values:        ' : ( RC EQ LL )
   CRT

I hope this help in what you are trying to accomplish.



------------------------------
Lance McMillin
Chatsworth CA US
------------------------------

Ok,  chasing my tail for a bit on this one.  

RC = 5061.10

LL = 5061.1

IF LL = RC THEN

CRT "WHY, THEY ARE NOT EQUAL"

END

They don't match!  why does it drop the 0 on the compare?  What is the correct way to fix.



------------------------------
Craig Curtis
System Programmer
Sevier Valley School District
Richfield UT US
------------------------------

This happens because the U2 processor (and others) automatically normalise numbers and values in arithmetic expressions to follow the rules and conventions of mathematics (and how numbers are stored in memory). 

Trailing zeros after a decimal point don't mean anything to mathematics and are classed as redundant. For consistency and memory storage efficiency, as soon as a numeric value is encountered, it is normalised and the redundant zeros are ignored, (the same with leading zeros) [000]123.321[000] => 123.321.

The values in your example are numbers so, they are normalised by the processor to values that can be acted on arithmetically. What I think you want to do is to coerce the variables to strings and then compare them based on their char values.

program one.off
   RC = 5061.1
   LL = 05061.10  ;* note leading/trailing redundant zeros
   ZZ = '5061.10' ;* note the quotes (' or " or \\ are fine)

   crt 'RC<=5061.1, LL<=05061.10, ZZ<="5061.10"'
   crt
   crt 'Assignment normalises a number and drops redundant zeros [RC , LL]:',RC,LL
   crt 'Assignment stores a quoted value into string storage and preserves trailing zeros [ZZ]:',ZZ
   crt
   * note, the following examples uses ZZ (with trailing zeros stored) as LL has already been normalised to a real number.
   crt 'Because they are both numeric values, RC=LL will be 1/mathematically equal:',(RC = LL)
   crt 'Using an expression normalises number values for arithmetic, so RC=ZZ (& ZZ=RC) will be 1/equal:',(RC = ZZ),(ZZ = RC)
   crt 'Strings containing numbers will be normalised for arithmetic, so as above, will be 1/equal:',('5061.1' = '5061.10')
   crt 'You can concatenate non-numeric character(s) to coerce as strings to be compared by char values ("x":val1="x":val2), so will be 0/unequal:',('x':5061.1 = 'x':'5061.10')
   crt
   crt 'You need to coerce both values to strings and then perform a string compare. To do that:'
   crt
   crt 'Use concatenation with any non-numeric char, eg $str=$difstr will be 0/unequal:',('$':RC = '$':ZZ),'or QUOTE(val):', (quote(RC)=quote(ZZ))
end



------------------------------
Stuart Boydell
AU
------------------------------