Question: Passing optional units to a proc

Hi,

I have aproc that takes a supplied electrical resistance and calculates the closest standard resistor value to it.

I would like the proc to work whether the supplies resistance has Units(ohm) or if it is free of units.  I am new to programming in Maple.  I have come up with the following but if there is a better way to do this, it would help me to get up to speed with Maple more quickly.

              TestParm := proc(r::algebraic)

              local r1::float, r2;



              # separate the units from the supplied parameter

              if type(r, with_unit(anything, r1, r2)) then

                             r1 := evalf(r1);

              else

                             r1 := evalf(r);

                             r2 := NULL;

              end if;

             

              [r1, r2];

end proc;

Thanks,

David

Please Wait...