ti/real.h
#include <ti/real.h>
Surprisingly, the TI-84 Plus CE is actually sold to students as a calculator and not a gaming console. TI actually even implemented an entire highly-accurate floating-point package!
TI’s floating-point routines use binary-coded decimal, in which each hexadecimal nibble represents one decimal digit.
Each real_t
has 14 digits (7 bytes) in the significand, an 8-bit exponent which the OS limits to +/- 99, and a sign byte.
They provide precision similar to a standard double
on a PC, albeit with a smaller exponent range.
Using real_t
is much slower than float
because of the vastly greater precision.
(Remember that the C SDK implements double
as float
, which is allowed by the C standard.)
The SDK calls them real_t
because float
is already taken.
The OS floating-point routines also support complex numbers quite well and transparently, but SDK support is not implemented.
A C++ wrapper is available as <ti/real>
but no documentation has been written.
Please see the examples in the standalone
folder and consult the header itself.
API Documentation
TI’s decimal floating-point library.
- Authors
Matt “MateoConLechuga” Waltz
Jacob “jacobly” Young
Defines
-
os_OP1
OP1 Variable.
-
os_OP2
OP2 Variable.
-
os_OP3
OP3 Variable.
-
os_OP4
OP4 Variable.
-
os_OP5
OP5 Variable.
-
os_OP6
OP6 Variable.
-
os_OP7
OP7 Variable.
-
os_StatVars
Contains data used by the statistics package.
If you use this area, mark it invalid:
#include <ti/vars.h> // . . . os_DelRes();
Type:
uint8_t[531]
-
os_Fin_N
-
os_Fin_I
-
os_Fin_PV
-
os_Fin_PMT
-
os_Fin_FV
-
os_Fin_PY
-
os_Fin_CY
-
os_Cal_N
-
os_Cal_I
-
os_Cal_PV
-
os_Cal_PMT
-
os_Cal_FV
-
os_Cal_PY
Functions
-
real_t os_RealAcosRad(const real_t *arg)
Takes the arccosine of a real_t, giving the answer in radians.
Note
Ensure -1 <= *arg <= 1, or program will crash.
-
real_t os_RealAsinRad(const real_t *arg)
Takes the arcsine of a real_t, giving the answer in radians.
Note
Ensure -1 <= *arg <= 1, or program will crash.
-
real_t os_RealAtanRad(const real_t *arg)
Takes the arctangent of a real_t, giving the answers in radians.
-
real_t os_RealExp(const real_t *arg)
Evaluates the exponential function (e^x, where e=2.717..) of a real_t.
-
real_t os_RealLog(const real_t *arg)
Takes the natural logarithm of a real_t.
Note
To take log base 10, divide this value by ln(10)
-
real_t os_RealGcd(const real_t *arg1, const real_t *arg2)
Calculates the Greatest Common Divisor of two real_t values.
-
real_t os_RealLcm(const real_t *arg1, const real_t *arg2)
Calculates the Least Common Multiple of two real_t values.
-
real_t os_RealMin(const real_t *arg1, const real_t *arg2)
Returns the smaller of two real_t values.
-
real_t os_RealNcr(const real_t *total, const real_t *num)
Calculates the value of nCr (binomial coefficient) for two real_t values.
-
real_t os_RealNpr(const real_t *total, const real_t *num)
Calculates the value of nPr (permutation number) for two real_t values.
-
real_t os_RealPow(const real_t *base, const real_t *exp)
Raises one real_t value to the power of another.
-
real_t os_RealRandInt(const real_t *min, const real_t *max)
Returns a random real_t between min and max.
-
real_t os_RealMod(const real_t *arg1, const real_t *arg2)
Calculates the remainder (modulo) of two real_t values.
-
real_t os_RealRound(const real_t *arg, char digits)
Rounds a real_t.
Note
digits must be in the range 0 - 9
- Parameters
arg – [in] Real variable.
digits – [in] Number of digits to round to.
-
int os_RealCompare(const real_t *arg1, const real_t *arg2)
Compares two real_t.
Note
os_RealCompare(arg1, arg2) op 0
computesarg1 op arg2
for any comparison operatorop
.- Parameters
arg1 – [in] Real variable 1.
arg2 – [in] Real variable 2.
- Returns
-1, 0, or 1 if arg1 is less than, equal to, or greater than arg2.
-
int24_t os_RealToInt24(const real_t *arg)
Converts a real_t to an integer.
Note
Saturates on overflow
- Parameters
arg – [in] Real variable.
-
real_t os_Int24ToReal(int24_t arg)
Converts an integer to a real_t.
Note
Saturates on overflow
- Parameters
arg – Integer value.
-
float os_RealToFloat(const real_t *arg)
Converts a real_t to a float.
Note
Saturates on overflow
- Parameters
arg – Real variable.
-
real_t os_FloatToReal(float arg)
Converts a float to a real_t.
Note
Saturates on overflow
- Parameters
arg – [in] Float value.
-
int os_RealToStr(char *result, const real_t *arg, int8_t maxLength, uint8_t mode, int8_t digits)
This converts a ti-float to a ti-ascii string.
- Parameters
result – [in] Zero terminated string copied to this address
arg – [in] Real to convert
maxLength – [in]
<=0: use default max length (14)
>0: max length of result, minimum of 6
mode – [in]
0: Use current mode for everything (digits ignored)
1: Normal mode
2: Sci mode
3: Eng mode
>4: Use current Normal/Sci/Eng mode (digits still used)digits – [in]
-1: Float mode
0-9: Fix # mode
- Returns
Length of result
-
real_t os_StrToReal(const char *string, char **end)
This converts a ti-ascii string to a ti-float.
String format regexp: / *[-\032+]?[0-9]*(.[0-9]*)?([eE\033][-\032+]?[0-9]*)?/
- Parameters
string – [in] TI-ascii string to convert
end – [in] If non-null, pointer to end of parsed number is stored here
- Returns
resulting TI-float; on exponent overflow this is +-9.9999999999999e99
-
struct real_t
- #include <real.h>
Structure of real variable type.
-
struct cplx_t
- #include <real.h>
Structure of complex variable type.