UNITS: odd behavior of "Mega" prefix

117 views
Skip to first unread message

Marco Polo

unread,
Jan 25, 2025, 3:45:58 PM1/25/25
to Free42 & Plus42
When dealing with pressure two common UOMs are MPa and kPa.
Apparently the Pa unit in Plus42 does not like to be "prefixed".
If I try to add 1_MPa (or 1_kPa) and 0_Pa I get " Invalid Unit".
It works correctly with other uoms (for example 1_Mm).

Thomas Okken

unread,
Jan 25, 2025, 5:05:35 PM1/25/25
to Free42 & Plus42
I can't reproduce that error:

            1_MPa      
             0_Pa      +
            1,000,000_Pa
            1_kPa      
             0_Pa      +
                1,000_Pa

Thomas Okken

unread,
Jan 25, 2025, 5:19:33 PM1/25/25
to Free42 & Plus42
However, I do notice that prefixed units don't work in the CUSTOM menu. I should fix that, but that doesn't seem to be the issue you are talking about; the error message when trying to use, say, MPa from CUSTOM is Label Not Found, not Invalid Unit.

Marco Polo

unread,
Jan 26, 2025, 4:06:13 AM1/26/25
to Free42 & Plus42
The "issue" was related to my attempt to find a workaround to the problem you just described: I had a unit definition for MPa which caused the problem.
I confirm that prefixed unit do not work in custom menu

Thomas Okken

unread,
Jan 26, 2025, 4:35:10 AM1/26/25
to Free42 & Plus42
How can I reproduce the Invalid Unit error you got? I'd like to make sure that error is not due to another bug, before I put out the release with the fix for the CUSTOM bug.

Marco Polo

unread,
Jan 26, 2025, 6:03:18 AM1/26/25
to Free42 & Plus42
Just define the custom unit MPa defined as 1_MPa and add it to Custom menu

Thomas Okken

unread,
Jan 26, 2025, 6:27:36 AM1/26/25
to Free42 & Plus42
Ah, OK. And then you get Invalid Unit because that's a circular definition.

So the error you reported in your first post is not a bug, but the inability to use prefixed units in CUSTOM is.

I already have a fix for the CUSTOM bug ready to go. I'll put out a new release shortly.

Marco Polo

unread,
Jan 26, 2025, 6:37:31 AM1/26/25
to Free42 & Plus42
As a side note, ASSIGN does not accept combined units (for example 1_kg/h), which shall be defined as custom units (es. 1_kg/h --> kgh) and thed assigned to key.
I suppose this is a by-design limitation of HP42s custom menus.
On 48/50 RPL machines you can add whatever you want directly in custom menu definition.

Thomas Okken

unread,
Jan 26, 2025, 7:26:17 AM1/26/25
to Free42 & Plus42
I can't reproduce that problem:

      ASSIGN "kgh" TO 01
        1_kg/h STO "kgh"
                   1_kgh
            0_g/s      +
    2.77777777778ᴇ-1_g/s

Thomas Okken

unread,
Jan 26, 2025, 7:30:00 AM1/26/25
to Free42 & Plus42
If I assign "kg/h" instead of "kgh", it works as well. With or without the CUSTOM fix in 1.2.1.
Message has been deleted

Thomas Okken

unread,
Jan 26, 2025, 7:39:26 AM1/26/25
to Free42 & Plus42
For what it's worth, there is no "by design" limitation in CUSTOM, other than the 7-character length limit.
What happens when you press a CUSTOM menu key is as follows:
  1. If the menu key is blank, beep.
  2. Look for a LBL that matches the menu key, and if it exists, XEQ it.
  3. Look for a variable that matches the menu key. If it exists and is a unit, apply it; else, RCL it.
  4. Look for a built-in function that matches the menu key, and if it exists, execute it.
  5. Check if the menu key looks like a unit, and if it does, apply it.
  6. XEQ the menu key, which will result in Label Not Found.
The check in step 5 was too restrictive, which caused prefixed units not to be recognized. I changed it in 1.2.1, and what it does now is to parse the key text as a unit, and if that succeeds, it additionally checks all the components, to see if they are built-in units or existing user-defined units

Marco Polo

unread,
Jan 26, 2025, 9:12:46 AM1/26/25
to Free42 & Plus42
Now i understand better the "problem" i was dealing with.
As a matter of fact i did not consider the limitation in lenght and assumed ASSIGN would accept labels or variables only. 
Hence the use of user defined units to get a workaround.
Now i understand that the user defined units are necessary only in the combined-unit lenght exceedes 7 characters.

I am using now 1.2.1 and works properly

Thomas Okken

unread,
Jan 26, 2025, 10:18:32 AM1/26/25
to Free42 & Plus42
On Sunday, January 26, 2025 at 3:12:46 PM UTC+1 mram...@gmail.com wrote:
Now i understand better the "problem" i was dealing with.
As a matter of fact i did not consider the limitation in lenght and assumed ASSIGN would accept labels or variables only. 
Hence the use of user defined units to get a workaround.
Now i understand that the user defined units are necessary only in the combined-unit lenght exceedes 7 characters.

That's how it used to work until recently. I even mentioned using user-defined units as a workaround in the Plus42 documentation.
I only added unit support for CUSTOM in release 1.1.16, last December.

I am using now 1.2.1 and works properly

Great! :-)

Thomas Okken

unread,
Jan 26, 2025, 5:07:43 PM1/26/25
to Free42 & Plus42
Argh, I just found another bug: prefixed user-defined units still don't work in CUSTOM. I could have sworn I tested that, but apparently not.
Release 1.2.2 coming up...
Reply all
Reply to author
Forward
0 new messages