This is a C header and source file containing constants and functions I find myself copy-and-pasting from previous programs I wrote.
This is intended for baremetal systems, where importing <math.h> may be undesirable.
Functions
This function formats a double number in engineering notation, from yocto- (10-24) to yotta- (1024).
String is 9 chars long, and is always right-justified so the prefix is always the 9th char.
returnStris the pointer to the string to pass the formatted string back to.inputNumis the double that is going to be converted to a string in engineering notation.sigFigsis the integer number of significant figures the number will be displayed with. Number of significant figures must be between or including 1 to 7.
0if a success1if error"SigFigErr"inreturnStrif significant figure not in range."OutOfRng"inreturnStrif value not in range.
This function finds the power of 10 for the engineering notation formatting of doubles.
The purpose of this function is to allow for specific formatting by only returning the exponent and allowing the formatting to be handled by the parent function.
inputNumis the double that will be used to find the exponent for engineering notation.
- integer exponent for engineering notation formatting
This function raises a double to an integer power and returns the product as a double.
baseis the type double base of the operation.poweris the exponent, and can be any whole integer.
- The value found by exponentiation (base^power).
This function returns the absolute value of a double.
value_inis the double to find the absolute value of.
- the absolute value of
value_in; |value_in|
This function converts an integer between and including 0 and 9 to its ASCII char representation.
IntToConvis the integer to convert between and including 0 and 9
- The ASCII representation of the integer. Returns 'E' if greater than 9 or less than 0.
This function converts an ASCII char between and including '0' and '9' to its integer equivalent.
CharToConvis the char to convert
- The converted integer value of the char. Returns 0xEEEE if not a number.
Constants
All of these constants are guarded in case they are defined elsewhere.TRUE: boolean 1FALSE: boolean 0PI: 3.1415926535897932384626433832795028841971693993751058209749445923