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

The following are finance variables that are always allocated.

They are all real_t.

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_RealCopy(const real_t *src)

Copies a real_t type.

Parameters

src[in] Pointer to original real_t

Returns

Copied real_t

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_RealCosRad(const real_t *arg)

Takes the cosine of a real_t given in radians.

real_t os_RealRadToDeg(const real_t *arg)

Converts a real_t from radians to degrees.

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_RealFloor(const real_t *arg)

Takes the floor of a real_t.

real_t os_RealFrac(const real_t *arg)

Extracts the fractional part of a real_t.

real_t os_RealRoundInt(const real_t *arg)

Rounds a real_t to the nearest integer.

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_RealNeg(const real_t *arg)

Negates a real_t.

real_t os_RealDegToRad(const real_t *arg)

Converts a real_t from degrees to radians.

real_t os_RealInv(const real_t *arg)

Takes the reciprocal of a real_t.

real_t os_RealSinRad(const real_t *arg)

Takes the sine of a real_t given in radians.

real_t os_RealSqrt(const real_t *arg)

Takes the square root of a real_t.

real_t os_RealTanRad(const real_t *arg)

Takes the tangent of a real_t given in radians.

real_t os_RealInt(const real_t *arg)

Extracts the integer part of a real_t.

cplx_t os_CplxSquare(const cplx_t *arg)

Calculates the square of a cplx_t.

real_t os_RealAdd(const real_t *arg1, const real_t *arg2)

Adds two real_t values.

real_t os_RealDiv(const real_t *arg1, const real_t *arg2)

Divides two real_t values.

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_RealMax(const real_t *arg1, const real_t *arg2)

Returns the larger 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_RealMul(const real_t *arg1, const real_t *arg2)

Multiplies 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_RealSub(const real_t *arg1, const real_t *arg2)

Subtracts 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 computes arg1 op arg2 for any comparison operator op.

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 an 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.

Public Members

int8_t sign
int8_t exp
uint8_t mant[7]
struct cplx_t
#include <real.h>

Structure of complex variable type.

Public Members

real_t real
real_t imag