Author Topic: Effects Of "cast.int" On Variables  (Read 251 times)

Darius1968

  • Hero Member
  • ***
  • Posts: 805
Effects Of "cast.int" On Variables
« on: November 25, 2021, 07:24:01 PM »
Given: 
Image File Dimensions:  2,118x3,000
Var Toy Expressions: 
     {File.Width|cast:int;math:div,{File.Height|cast:int},4} = 70.6000
                             {File.Width|math:div,{File.Height},4} =   0.7060

Considering the above two expressions, the 2nd (without cast:int) gives the expected result, whereas, in the presence of "cast.int", I get something, a magnitude x100.  The 1st expression (with cast.int), recommended, here, on the forum, is supposed to give a precise value for aspect ratio.  But, it so appears, that, to get that precise value, I actually have to omit the "cast:int"-part of the expression.  So, what is the use of "cast.int", and what is it doing? 
« Last Edit: November 25, 2021, 07:28:19 PM by Darius1968 »

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Effects Of "cast.int" On Variables
« Reply #1 on: November 25, 2021, 07:55:27 PM »
cast.int does not exist.
All variables are strings, formatted using the matching formatting for your locale and user settings, including . and , to separate decimals and thousands.
Is the info in the help not clear? Did you Look at the uncasted result of File.Width and File.Height? What locale do you use?

A simple test like

{File.Width} => {File.Width|cast:int}

should make it very clear what cast does. It converts text into a number.

6,400 => 6400

or, when you live in Germany or other EU countries

6.400 => 6400

You cannot do math with strings. In your second expression you don't cast. Depending on what thousand separator your locale uses, results are undefined. May work when both width and height is less than 1,000.
« Last Edit: November 25, 2021, 07:57:54 PM by Mario »

Darius1968

  • Hero Member
  • ***
  • Posts: 805
Re: Effects Of "cast.int" On Variables
« Reply #2 on: November 25, 2021, 08:03:55 PM »
In my cast:
{File.Width} => {File.Width|cast:int} gives...
         2,118 =>2,118

so...
the cast:int is not changing the width into 2118.  So, what is set, on my end, to give this result? 

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Effects Of "cast.int" On Variables
« Reply #3 on: November 25, 2021, 08:28:04 PM »
Show me in VarToy.
You did not answer my questions. Please do. Locale, number format set for Windows, list separator set for Windows etc. All this impacts how Windows parses numbers and formats them.

« Last Edit: November 25, 2021, 08:33:24 PM by Mario »

sinus

  • Global Moderator
  • *****
  • Posts: 4489
  • IMatch-User since 2001 (IMatch 3.6)
Re: Effects Of "cast.int" On Variables
« Reply #4 on: November 25, 2021, 08:48:15 PM »
On my system, just checked:

Var Toy gives:

{File.Width} gives 6.016
{File.Width|cast:int} gives 6016
 
Best wishes from Switzerland! :-)
Markus

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Effects Of "cast.int" On Variables
« Reply #5 on: November 25, 2021, 09:01:23 PM »
Thanks for checking. Can somebody with a locale using , as the thousands separator (1,024 instead of 1.024) check the variable in VarToy please?

Darius1968

  • Hero Member
  • ***
  • Posts: 805
Re: Effects Of "cast.int" On Variables
« Reply #6 on: November 25, 2021, 11:10:00 PM »
Here's my screenshot. 

JohnZeman

  • Global Moderator
  • *****
  • Posts: 1463
  • I'm too damn old to act my age.
Re: Effects Of "cast.int" On Variables
« Reply #7 on: November 25, 2021, 11:15:28 PM »
Thanks for checking. Can somebody with a locale using , as the thousands separator (1,024 instead of 1.024) check the variable in VarToy please?

On my system here in the great state of Iowa in the USA not only does it not return an unformatted integer it seems to depend upon the camera/lens combination as to what it returns.
« Last Edit: November 26, 2021, 05:22:00 AM by JohnZeman »

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Effects Of "cast.int" On Variables
« Reply #8 on: November 25, 2021, 11:49:19 PM »
Strange.
When you look at the Windows number settings, what is a) the thousands, b) decimal, c) list separator on your system?

JohnZeman

  • Global Moderator
  • *****
  • Posts: 1463
  • I'm too damn old to act my age.
Re: Effects Of "cast.int" On Variables
« Reply #9 on: November 26, 2021, 12:13:44 AM »
Screenshot of my Windows configuration for numbers format attached.

I'm not sure about the decimal separator but for the other two it's a , (comma).


Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Effects Of "cast.int" On Variables
« Reply #10 on: November 26, 2021, 09:03:07 AM »
List separator is a comma, maybe this is what's causing the issue.
When IMatch casts variables, it needs to  check if the result of the variable is a list. Like an enumeration, e.g. categories, keywords and similar repeatable tag and Attribute values.
IMatch separates repeatable values in variables using the list separator configured in Windows for the current user. In your case, a comma.
So a value like 1,024 looks to IMatch like a list of two values: (1), (024) and it then casts each of these values separately and returns them.
If this is the problem, I'm not sure how to handle this. The cast function has no idea how the value it must cast has been produced. It may be the direct output of the variable or it may be the result of 5 other functions which have somehow produced that value containing the list separator character...

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 30082
Re: Effects Of "cast.int" On Variables
« Reply #11 on: November 26, 2021, 01:59:24 PM »
I have solved this problem by checking if the thousand grouping symbol/character has been set to the same symbol/character as the list separator. In this case, cast (and some other functions) no longer split the variable value. This fixes this particular issue.

But I wonder, why is the same letter used for thousand groupings and list? Does this not confuse other applications too?
What if we have a value like 1,234,567
Is this the number 1234567  (formatted with thousand groupings) or is this  the list of numbers (1) (234) (456) ?

In Germany we use

. Thousand separator
, Decimal comma
; List separator

For countries which use , as the thousand separator and . as the decimal point, would not be ; as a list separator better than using a , for this as well? To avoid confusion when formatting or processing lists of numbers?

I have checked the help and, to my surprise (and I have written it) this particular problem is even mentioned in a yellow warning box, next to the cast documentation:



I can remove that now and replace it with a comment that explains that if the thousand grouping symbol and the list separator are the same, cast no longer handles lists.

« Last Edit: November 26, 2021, 02:39:09 PM by Mario »

Darius1968

  • Hero Member
  • ***
  • Posts: 805
Re: Effects Of "cast.int" On Variables
« Reply #12 on: November 26, 2021, 06:05:53 PM »
I see, this post has been referenced and included, as a bug-fix, in the list, for the next release.  So, accordingly, should this post also be, moved to the Bug Reports section, of this forum?