Showing posts with label measuring. Show all posts
Showing posts with label measuring. Show all posts

Sunday, October 21, 2018

HP Prime: Feet/Feet-Inch-Fraction Conversions (compact format)

HP Prime:  Feet/Feet-Inch-Fraction Conversions  (compact format)

Introduction

The two functions presented on this blog entry are FIFT (feet-inches-sixteenth of inches to feet) and FTFI (feet to feet-inches-sixteenth of inches).  The format of the feet-inches-sixteenth of inches are as follows:

FF: feet
II: inches
NN: sixteenth of an inch

Example:  4.0107 -> 4 feet 1 inch 7/16
Example: 5.1108 -> 5 feet 11 inches 1/2
Example: 3.06142 -> 3 feet 6 inches 14.2/16

There is no rounding or fraction simplification involved with this format.

HP Prime Program FIFT:    FF.IINN to Feet

EXPORT FIFT(X)
BEGIN
// 2018-10-08 EWS
// FF.II16 → FEET
LOCAL Y,Z;
Y:=100*FP(X);
Y:=(IP(Y)+100*FP(Y)/16)/12;
Z:=IP(X)+Y;
RETURN Z;
END;

Examples:

FIFT(6.111) returns 6.96875   (6 ft 11 in 10/16 -> 6.96875 ft)
FIFT(0.0808) returns 0.70833333333 (8 in 8/16 (8 in 1/2) -> 0.70833333333 ft)

HP Prime Program FTFI:  Feet to FF.IINN


EXPORT FTFI(X)
BEGIN
// 2018-10-08 EWS
// FEET → FF.II16
LOCAL Y,Z;
Y:=FP(X)*12;
Z:=IP(Y)/100; 
Y:=FP(Y)*16/10000;
Z:=IP(X)+Z+Y;
RETURN Z;
END;

Examples:

FTFI(5.78125) returns 5.0906  (5.78125 ft -> 5 ft 9 in 6/16  (5 ft 9 in 3/8))
FTFI(4.05) returns 4.00096  (4.05 ft -> 4 ft 9.6/16 in)

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Sunday, November 26, 2017

Rounding to the Nearest Reciprocal (HP Prime, TI-84 Plus CE, Casio fx-CG 50)

Rounding to the Nearest Reciprocal   (HP Prime, TI-84 Plus CE, Casio fx-CG 50)

Introduction

The program ROUNDRCP rounds a number to the nearest 1/n. This function can come in handy in several applications, for example, when working with construction or measuring, when have to round results to the nearest eighth (1/8), inch (1/12) or sixteenth (1/16).

Presented here are versions for the HP Prime, TI-84 Plus CE, and Casio fx-CG 50.

HP Prime:  ROUNDRCP

EXPORT ROUNDRCP(a,n)
BEGIN
// Round a to the nearest 1/n
// 2017-11-21 EWS
LOCAL w;
w:=FP(ABS(a))*n;
w:=ROUND(w,0);
RETURN IP(a)+SIGN(a)*(w/n);
END;


The TI-84 Plus CE and Casio fx-CG 50 versions store the answer in X.

TI-84 Plus CE ROUNDRCP

"EWS 2017-11-21"
Input "NUMBER:",A
Input "TO 1/NTH:",N
fPart(abs(A))*N→W
round(W,0)→W
If A<0
Then
iPart(A)-(W/N)→X
Else
iPart(A)+(W/N)→X
End
Disp "X:",X


Casio fx-CG 50 ROUNDRCP

“NUMBER”?→A
“TO 1÷NTH”?→N
Frac ((Abs A))*N→N
RndFix(W,0)→W
If A<0
Then
Int (A)-(W÷N)→X
Else
Int(A)+(W÷N)→X
IfEnd
“X:”
X

Examples

Round π to the nearest 1/4:
ROUNDRCP(π, 4):  3.25 = 13/4

Round e^2 to the nearest 1/100:
ROUNDRCP(e^2, 100): 7.39 = 739/100

Round 1/4 + 2/7 + 3 1/3 to the nearest 1/16:
ROUNDRCP(1/4 + 2/7 + 3 + 1/3, 16):  3.875 = 31/8
(thank you to Joe Horn for pointing out my error, it's correct now.)

Tips 

If you do not have the sign (signum) function, you can compensate by the following code:

If X<0
Then
Return -1  (subtract operation)
Else
Return 1 (addition operation)
End

If your calculator does not have the Round to any number of decimal points function, such as the Casio fx-5800p or fx-3650p, you can manipulate the modes and use the Rnd function and a switch of modes, like this code:

Fix 0
X  (put number to round in display)
Rnd
Float/Norm (1/2)

Eddie


This blog is property of Edward Shore, 2017

Python – Earth’s Radius and Gravity in US Units

Python – Earth’s Radius and Gravity in US Units Introduction The following script, gravus2.py, estimates the Earth’s gravity i...