Post Reply 
REQUEST: Significant Digit Calculator
01-24-2018, 03:19 PM (This post was last modified: 01-25-2018 04:37 PM by lschroeder1947.)
Post: #5
RE: REQUEST: Significant Digit Calculator
(01-22-2018 03:58 AM)Joe Horn Wrote:  
(01-22-2018 01:32 AM)Helge Gabert Wrote:  ROUND(7.8676,-2) returns 7.9 (two sig. digits).

Other functions (like ROUND) which let you control the number of significant digits include:

TRUNCATE(7.8676,-2) --> 7.8 (notice the negative sign)
evalf(7.8676,2) --> 7.9 (the second argument's sign is ignored)
approx(7.8676,2) --> 7.9 (the second argument's sign is ignored)

And if you want all your results to automatically be rounded to 4 significant digits, just set the Number Format (in Home Settings) to Scientific 3.

Prime's built-in Help system, with its own search function, is your friend. Smile

Edit 1: 1/25/2018

Post 2 and 3 from my thread on Xcas videos have screenshots showing evalf(Expr,[Integer]) being used in various situations. Below are our friends, the help screens that Joe mentioned. It looks to me like Round (value, [places]) would be the most appropriate because it can handle place value when we add/subt and significant digits when mult/div/powers.

[Image: help.png]

Post 1 examples implemented for Joe's other functions.

[Image: sgn_digits.png]

End Edit 1

(01-22-2018 12:56 AM)Tim Wessman Wrote:  Please give an example of how this is done?

The only things I have seen are some very limited programs that aren't general use and hence not very useful.

In my book HP Prime Guide Algebra Fundamentals I wrote a program to store current settings, switch to scientific with desired digits, and switch back to original settings. The main feature of the book is on using the CAS view and HOME view to help you with learning or reviewing Algebra. I am new at programming the Prime, so hope you can be a little forgiving at my programming. As Tim said most scientific notation programs are limited and mine probably falls in that category. I thought it might be useful to some. In the book it takes several pages to document its creation and use. Below are a couple of excerpts from the book.

[Image: sc_notation_1.gif]

Edit 2: 1/25/2018

As Joe said you could just set the number of digits manually. The screen below shows the result from toggling from 5 digits back to original settings. Be careful the Home Setting "Scientific" "Digits" is different than significant digits. For Joe's above example we would set scdigits(3) to get 4 significant digits. The bad side effect of the changing the Home Setting or using my function scdigit is all non exact values in the History area are changed. By using the user "Apps" key at the end everything in History area will be returned to its original values.

End Edit 2

[Image: sc_notation_2.gif]

PHP Code:
Export gclsdigitsgclscountgclshformatgclshdigits;

K_Eex();
K_Apps();
first();

EXPORT scdgts(digits)
BEGIN
 LOCAL message
;
 
first( );
 IF (
digits >= AND digits <= 11THEN
  gclsdigits 
:= digits;
  
HFormat := 2;
  
HDigits := gclsdigits;
  
message := "Scientific";
 ELSE
  
message := "Error: Range 0-11"
 
END;
 RETURN 
message;
END;

KEY K_Eex()
BEGIN
  first
();
  IF 
HFormat <> 2 THEN
    HFormat 
:= 2;
    
HDigits := gclsdigits;
  ELSE
    
HFormat := 0;
  
END;
  
STARTVIEW(-1,1);
  RETURN 
10;
END;

KEY K_Apps()
BEGIN
LOCAL message
;
 
message := "Unknown";
 IF 
gclscount <> 0 THEN
  HFormat 
:= gclshformat;
  
HDigits := gclshdigits;
  
gclscount := 0;
  
gclsdigits := 0;
  CASE
   IF 
gclshformat == 0 THEN message := "Standard"END;
   IF 
gclshformat == 1 THEN message := "Fixed"END;
   IF 
gclshformat == 2 THEN message := "Scientific"END;
   IF 
gclshformat == 3 THEN message := "Engineering"END;
   IF 
gclshformat == 4 THEN message := "Floating"END;
   IF 
gclshformat == 5 THEN message := "Rounded"END;
  
END;
 
END;
 
STARTVIEW(-1,1);
 RETURN 
"Restored Number Format " message " - Press Esc";
END;

first()
BEGIN
 gclscount 
:= gclscount 1;
 IF 
gclscount == 1 THEN
   gclsdigits 
:= 6;
   
gclshformat := HFormat;
   
gclshdigits := HDigits;
 
END;
END


Attached File(s)
.hpprgm  Key_user.hpprgm (Size: 1.21 KB / Downloads: 1)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: REQUEST: Significant Digit Calculator - lschroeder1947 - 01-24-2018 03:19 PM



User(s) browsing this thread: 1 Guest(s)