View Issue Details

IDProjectCategoryView StatusLast Update
0004037ExpressionsFeaturepublic2021-02-06 06:30
Reporteruwestoehr Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
Status newResolutionopen 
Product Version0.18 
Target Version0.20 
Summary0004037: rewrite unit handling so that unit prefixes will be recognized
DescriptionCurrently we have the case that the expression parser knows units with prefixes, e.g. "mA". For other units like e.g. "j", it does not know any prefix.

To overcome this, the expression parser must be rewritten so that it recognizes these prefixes:
n, mu/µ, m, k, M, G
and connects them automatically to the unit that follows directly on the prefix letter.

So "ncd" will be recognized as "we have 'n' -> nano (10^-9), the next letter is 'c' which could be part of a known unit that begins with 'c', the next letter is 'd' so we know we have the unit "cd" with the prefix 'n'.
However "n A" will be recognized as "we have 'n' -> nano (10^-9), the next letter is ' ' (space), so we don't have a unit connected to the prefix letter 'n' and we issue an error.

This method would lead to
- consistent handling of all units
- support for unit prefixes for all units
Additional InformationForum thread: https://forum.freecadweb.org/viewtopic.php?f=38&t=37164

The idea was approved as useful by @berndhahnebach
Tagsexpressions, units
FreeCAD Information

Activities

berndhahnebach

2019-06-26 20:20

developer   ~0013313

https://en.wikipedia.org/wiki/Unit_prefix

openBrain

2019-06-30 14:15

developer   ~0013321

Be very careful to side effects ! I'd not want that 'min' unit being considered as "milli-inch" instead of the correct "minute". ;)

uwestoehr

2019-07-01 09:07

manager   ~0013326

> I'd not want that 'min' unit being considered as "milli-inch"

Yes, the procedure should be
1. read the whole given unit and if it is known like "min" then nothing is done and the unit is taken as it is
2.1 if the unit is unknown, check if it begins with a known letter of unit prefixes
2.2 if yes, read the unit beginning with the second character and if this is a known unit, use it multiplied with the factor according to the read unit prefix
3. if 1. and 2. did not lead to a known unit, deny the unit and issue an error message

ezzieyguywuf

2019-11-29 13:40

developer   ~0013851

I think a better approach is perhaps to hard-code a set of given prefixes to units that they are compatible with.

For example, “milli”, “kilo”, etc, are commonly accepted with metric units.

Not so much for imperial- I’ve never heard of a milli-inch

yorik

2022-03-03 13:55

administrator   ~0016789

This ticket has been migrated to GitHub as issue 5955.

Issue History

Date Modified Username Field Change
2019-06-25 23:36 uwestoehr New Issue
2019-06-25 23:36 uwestoehr Tag Attached: expressions
2019-06-25 23:36 uwestoehr Tag Attached: units
2019-06-25 23:36 uwestoehr Additional Information Updated
2019-06-25 23:36 uwestoehr Additional Information Updated
2019-06-26 20:20 berndhahnebach Note Added: 0013313
2019-06-30 14:15 openBrain Note Added: 0013321
2019-07-01 09:07 uwestoehr Note Added: 0013326
2019-11-29 13:40 ezzieyguywuf Note Added: 0013851
2021-02-06 06:30 abdullah Target Version => 0.20