HP Forums
Adding Table of constant Units? how? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Adding Table of constant Units? how? (/thread-6775.html)



Adding Table of constant Units? how? - tom234 - 09-01-2016 06:07 AM

Hello There,


RE: Adding Table of constant Units? how? - Thomas_Sch - 09-02-2016 06:18 AM

Unfortunately I have no solution yet.
Maybe your question would be more visible in the other sub forum: "HP Prime" http://www.hpmuseum.org/forum/forum-5.html


RE: Adding Table of constant Units? how? - Didier Lachieze - 09-04-2016 07:31 AM

I don't think you can define constants per se in the Prime but what you can do is defining global variables that you'll be able to use where you want. However you need to ensure that the name of your global variables don't conflict with the HP Prime predefined variables. Also as they are variables and not constants they can be modified so beware how you use them!

For example you can create a new program called "CONSTANTS", remove the CONSTANT template inside and just add these two lines and press Check:
Code:
EXPORT AU:=149597870691;
EXPORT ly:=9.460536207ᴇ12;

You have now created two global variables: ly light year in km and AU astronomical unit in km. You can use these variables to calculate for example the value of a light year in AU in this test program :
Code:
EXPORT TEST()
BEGIN
  RETURN(ly/AU);
END;



RE: Adding Table of constant Units? how? - DrD - 09-04-2016 09:23 AM

The exported variables are available outside of programs, but there is no way to write protect them. They can easily be changed via command line entry, or other programs, so constants may not be exactly that!


RE: Adding Table of constant Units? how? - Arno K - 09-04-2016 10:00 AM

Perhaps creating a new application and assigning all needed constants in the start() part could help.
Arno


RE: Adding Table of constant Units? how? - StephenG1CMZ - 09-04-2016 06:50 PM

If you need your constants to include units rather than just numbers, there is a complication: CONVERT's second parameter must be 1 unit, not 0.5 unit (using 0.5 in this example to convert between HP AU and my own AU, to make the output value obviously different.

Code:


 EXPORT MYAU:=0.5;//MULTIPLIER TO CONVERT BETWEEN HP AU AND MY AU
 EXPORT MYAUinAU:=0.5*1_au;//DOESNT WORK
 EXPORT LY()
 BEGIN
  PRINT();
  PRINT("LYR in HP AU: "+CONVERT(1_lyr,1_au));
  PRINT("LYR in MY AU: "+MYAU*CONVERT(1_lyr,1_au));
  PRINT("LYR NOT in my AU: "+CONVERT(1_lyr,MYAUinAU));//users may not expect this
 END;


To make Using your own units possible you would want CONVERT to notice that MYAUinAU was a value other than 1 unit and modify the number returned accordingly.


RE: Adding Table of constant Units? how? - tom234 - 09-09-2016 06:06 PM

(09-04-2016 07:31 AM)Didier Lachieze Wrote:  I don't think you can define constants per se in the Prime but what you can do is defining global variables that you'll be able to use where you want. However you need to ensure that the name of your global variables don't conflict with the HP Prime predefined variables. Also as they are variables and not constants they can be modified so beware how you use them!

For example you can create a new program called "CONSTANTS", remove the CONSTANT template inside and just add these two lines and press Check:
Code:
EXPORT AU:=149597870691;
EXPORT ly:=9.460536207ᴇ12;

You have now created two global variables: ly light year in km and AU astronomical unit in km. You can use these variables to calculate for example the value of a light year in AU in this test program :
Code:
EXPORT TEST()
BEGIN
  RETURN(ly/AU);
END;

Thank you you solved the problem and answered my question thank you very much Smile


RE: Adding Table of constant Units? how? - tom234 - 09-09-2016 06:12 PM

(09-04-2016 06:50 PM)StephenG1CMZ Wrote:  If you need your constants to include units rather than just numbers, there is a complication: CONVERT's second parameter must be 1 unit, not 0.5 unit (using 0.5 in this example to convert between HP AU and my own AU, to make the output value obviously different.

Code:


 EXPORT MYAU:=0.5;//MULTIPLIER TO CONVERT BETWEEN HP AU AND MY AU
 EXPORT MYAUinAU:=0.5*1_au;//DOESNT WORK
 EXPORT LY()
 BEGIN
  PRINT();
  PRINT("LYR in HP AU: "+CONVERT(1_lyr,1_au));
  PRINT("LYR in MY AU: "+MYAU*CONVERT(1_lyr,1_au));
  PRINT("LYR NOT in my AU: "+CONVERT(1_lyr,MYAUinAU));//users may not expect this
 END;


To make Using your own units possible you would want CONVERT to notice that MYAUinAU was a value other than 1 unit and modify the number returned accordingly.

///////////////////
with all due respect to all the programmers C++, Perl, Ruby are a lot easier and more powerful a language than HP C. its making me second guess just using an app on my iPhone to do this calculator thing.
Is there a code or language PDF for HP C(language)????????


RE: Adding Table of constant Units? how? - StephenG1CMZ - 09-10-2016 08:22 AM

(09-09-2016 06:12 PM)tom234 Wrote:  
(09-04-2016 06:50 PM)StephenG1CMZ Wrote:  If you need your constants to include units rather than just numbers, there is a complication: CONVERT's second parameter must be 1 unit, not 0.5 unit (using 0.5 in this example to convert between HP AU and my own AU, to make the output value obviously different.

Code:


 EXPORT MYAU:=0.5;//MULTIPLIER TO CONVERT BETWEEN HP AU AND MY AU
 EXPORT MYAUinAU:=0.5*1_au;//DOESNT WORK
 EXPORT LY()
 BEGIN
  PRINT();
  PRINT("LYR in HP AU: "+CONVERT(1_lyr,1_au));
  PRINT("LYR in MY AU: "+MYAU*CONVERT(1_lyr,1_au));
  PRINT("LYR NOT in my AU: "+CONVERT(1_lyr,MYAUinAU));//users may not expect this
 END;


To make Using your own units possible you would want CONVERT to notice that MYAUinAU was a value other than 1 unit and modify the number returned accordingly.

///////////////////
with all due respect to all the programmers C++, Perl, Ruby are a lot easier and more powerful a language than HP C. its making me second guess just using an app on my iPhone to do this calculator thing.
Is there a code or language PDF for HP C(language)????????

The language users use to program on the HP Prime is called PPL (Prime Programming Language).. Some have referred to it as being like Pascal.
www://http://support.hp.com/us-en/product/HP-Prime-Graphing-Calculator/5367459/model/5367460/manuals
The most up to date guide to syntax will be that in the on-calculator help.


RE: Adding Table of constant Units? how? - tom234 - 09-22-2016 07:11 PM

Ty very much to one and all Smile
your help was greatly appreciated Smile


RE: Adding Table of constant Units? how? - tom234 - 06-03-2019 07:48 PM

(09-04-2016 07:31 AM)Didier Lachieze Wrote:  I don't think you can define constants per se in the Prime but what you can do is defining global variables that you'll be able to use where you want. However you need to ensure that the name of your global variables don't conflict with the HP Prime predefined variables. Also as they are variables and not constants they can be modified so beware how you use them!

For example you can create a new program called "CONSTANTS", remove the CONSTANT template inside and just add these two lines and press Check:
Code:
EXPORT AU:=149597870691;
EXPORT ly:=9.460536207ᴇ12;

You have now created two global variables: ly light year in km and AU astronomical unit in km. You can use these variables to calculate for example the value of a light year in AU in this test program :
Code:
EXPORT TEST()
BEGIN
  RETURN(ly/AU);
END;

TY