C99 support functions

Introduction and Overview

The C99 support library (C99) provides a number of functions required by the C99 compiler and usable by other clients. The library has no data requirements. The library has a SharedCLibrary library chunk ID of 5.

Technical Details

Floating point support

Many of the functions are provided in two variants, distinguished by a 'f' (or no) or 'd' suffix. These indicate the routine is expected to provide a float (32bit FP) or double (64bit FP) argument. Except where mentioned, floating point arguments are passed in ARM registers.

'long long' support

A number of 'long long' support functions are also provided. These provide additional support to that provided by the C99Low library explicitly for C99-specification support.

A 'long long' is a 64bit value which can be signed or unsigned. It is represented by two 32bit little-endian words, with the low word stored first. When passed to functions, a 'long long' can be effectively represented as a structure thus:

typedef __value_in_regs struct longlong_s {long lo;
unsigned long hi;
} longlong_t;

In this form, values are passed to functions as if there were two registers containing the lo and hi values.

'intmax_t' support

The 'intmax_t' type is provided in an identical manner to that of the 'long long' support. Parameters passed to functions and returned by this type are passed in two registers containing the low and high values.

Calling conventions

All functions within the library use APCS-R or APCS-32 (dependent on linkage) calling conventions.

Functions

The entry numbers are those of the entries within the C99 library chunk.

Number classification

EntryFunctionDescription
0int __fpclassifyf(float);float version
1int __fpclassifyd(double);double version

Returns a classification of the floating point argument passed, as specified below:

ValueMeaning
0Value is zero
1Value is a sub-normal FP value
2Value is a normal FP value
3Value is an infinity FP value
4Value is Not-A-Number (NAN) FP value

Note: FP values are passed in FP registers.

EntryFunctionDescription
2int __signbitf(float);float version
3int __signbitd(double);double version

Returns the value of the sign bit for the floating point argument passed. 1 if the sign bit is set, 0 if the sign bit is clear.

Note: FP values are passed in FP registers.

EntryFunctionDescription
4double copysign(double x, double y);double version
5float copysignf(float x, float y);float version

Returns a floating point value whose sign matches that of y, and whose magnitude is that of x. Effectively, copies the sign of y into x and returns it.

Note: FP values are passed in FP registers.

EntryFunctionDescription
6double nan(const char *tag);double version
7float nanf(const char *tag);float version

Returns a Not-A-Number (NAN) FP value. The value of tag is implementation defined. Current implementations ignore the value of tag.

Extra floating point functions

EntryFunctionDescription
8double nextafter(double x, double y);double version
9float nextafterf(float x, float y);float version

Returns the next representable value in the specified format after x in the direction of y.

EntryFunctionDescription
10double fdim(double x, double y);double version
11float fdimf(float x, float y);float version

Determines the positive difference between the arguments:

  • if x > y, returns x-y
  • if x <= y, returns +0

A range error may occur. Returns the positive difference value.

EntryFunctionDescription
12double fmax(double x, double y);double version
13float fmaxf(float x, float y);float version

Returns the higher of the two arguments.

EntryFunctionDescription
14double fmin(double x, double y);double version
15float fminf(float x, float y);float version

Returns the lower of the two arguments.

EntryFunctionDescription
16float fabsf(float x);Returns the absolute value of the argument.
EntryFunctionDescription
17double hypot(double x, double y);double version
18float hypotf(float x, float y);float version

Returns the square root of the sum of the squares of x and y, without undue overflow or underflow. A range error may occur.

Floating Point Environment operations

EntryFunctionDescription
19int feclearexcept(int exceptions);Clears floating point exceptions. Returns the bit mask of the exceptions which could not be cleared.

The exceptions bit mask is:

BitException
0Invalid operation
1Division by zero
2Overflow
3Underflow
4Inexact
EntryFunctionDescription
20int fegetexceptflag(unsigned int *flagsp, int exceptions);Reads the representation of the FP status flags indicated by the exceptions arguments. Returns zero if successful, non-zero if failed.
EntryFunctionDescription
21int feraiseexcept(int exceptions);Attempts to raise the floating point exceptions specified within the exceptions flags. Returns zero if successful, non-zero if failed.
EntryFunctionDescription
22int fesetexceptflag(unsigned int *flagsp, int exceptions);Attempts to set the status flags indicated by the exceptions argument to those stored in the value pointed to by flagsp. This function can be used together with fegetexceptflag() to preserve and restore floating point status flags. Returns zero if successful, or non-zero if failed.
EntryFunctionDescription
23int fetestexcept(int exceptions);Determines which of the exceptions specified in the argument are currently set. Returns the exceptions which are currently set, from those specified within the argument.
EntryFunctionDescription
24int fegetround(void);Reads the current rounding direction. Returns 0 indicating 'round to nearest'. The current implementation of the ARM FP system cannot change its rounding direction at runtime.
EntryFunctionDescription
25int fesetround(int direction);Changes the rounding direction. Returns 0 indicating success if the direction specified was 0, or 1 indicating a failure otherwise.
EntryFunctionDescription
26int fegetenv(const fenv_t *envp);Reads the current floating point environment into the structure specified. The structure must be 6 words long. Returns 0 if successful, or 1 if failed.
EntryFunctionDescription
27int feholdexcept(const fenv_t *envp);Reads the current floating point environment into the structure specified, clears any pending exceptions and disables all floating point exceptions. Returns 0 if successful, or 1 if failed.
EntryFunctionDescription
28int fesetenv(const fenv_t *envp);Attempts to set the floating point environment to that stored in the argument. No exceptions are raised. Returns 0 if successful, or 1 if failed.
EntryFunctionDescription
29int feupdateenv(const fenv_t *envp);Attempts to set the floating point environment to that stored in the argument. Exceptions are then raised. Returns 0 if successful, or 1 if failed.

Extended string operations

EntryFunctionDescription
30int _snprintf(char *output, size_t max, const char *format, ...);Integer-only form of sprintf, limited to max output bytes. Consult the C specification for details of the format parameters. Returns the number of bytes which have been written to the output buffer, or would have been written if the buffer had been long enough.
EntryFunctionDescription
31int snprintf(char *output, size_t max, const char *format, ...);Form of sprintf, limited to max output bytes. Consult the C specification for details of the format parameters. Returns the number of bytes which have been written to the output buffer, or would have been written if the buffer had been long enough.
EntryFunctionDescription
32int vsnprintf(char *output, size_t max, const char *format, va_list ap);Variadic arguments form of snprintf. Consult the C specification for details of the format parameters. Returns the number of bytes which have been written to the output buffer, or would have been written if the buffer had been long enough.
EntryFunctionDescription
33int vfscanf(FILE *f, const char *format, va_list);Variadic form of fscanf. Consult the C specification for details of the format parameters. Returns the number of arguments processed, or EOF if failed before any conversion.
EntryFunctionDescription
34int vscanf(const char *format, va_list);Variadic form of scanf. Consult the C specification for details of the format parameters. Returns the number of arguments processed, or EOF if failed before any conversion.
EntryFunctionDescription
35int vsscanf(const char *string, const char *format, va_list);Variadic form of sscanf. Consult the C specification for details of the format parameters. Returns the number of arguments processed, or EOF if failed before any conversion.

Rounding and remainder functions

EntryFunctionDescription
36float ceilf(float x);Returns the smallest integer not less than x.
EntryFunctionDescription
37float floorf(float x);Returns the largest integer not greater than x.
EntryFunctionDescription
38double nearbyint(double x);double version
39float nearbyintf(float x);float version

Rounds its argument to an integer value, using the current rounding direction. Does not raise the inexact exception.

EntryFunctionDescription
40double rint(double x);double version
41float rintf(float x);float version
42long int lrint(double x);double version, returning a long int
43long int lrintf(float x);float version, returning a long int

Rounds its argument to an integer value, using the current rounding direction. Raises "inexact" if the result differs from the argument.

EntryFunctionDescription
44double round(double x);double version
45float roundf(float x);float version
46long int lround(double x);double version, returning a long int
47long int lroundf(float x);float version, returning a long int

Rounds its argument to the nearest integer value, rounding halfway cases away from zero.

EntryFunctionDescription
48double trunc(double x);double version
49float truncf(float x);float version

Rounds its argument to the integer value, nearest to but no larger in magnitude than the argument.

EntryFunctionDescription
50double remainder(double x, double y);double version
51float remainderf(float x, float y);float version

Computes the remainder x REM y required by IEEE 754.

Long Long operations

EntryFunctionDescription
52long long llabs(long long j);Returns the absolute value of j.
EntryFunctionDescription
53lldiv_t lldiv(long long j, long long k);Computes numer / denom and numer % denom in a single operation. Returns a structure of type lldiv_t, comprising both the quotient and the remainder.

typedef struct lldiv_t { long long quot;
long long rem;
} lldiv_t;

String conversion functions

EntryFunctionDescription
54long long atoll(const char *s);Returns the value of the string in s. This is equivalent to strtoll(s, (char **)NULL, 10); with the exception that errno is unaffected by the conversion.
EntryFunctionDescription
55long long strtoll(const char *s, char **e, int b);Returns the value of the string in s, given in base b, storing the end of the conversion in pointer at e. e may be NULL if no end pointer is required. b may be 0 to indicate that the number is decimal, octal, or hexadecimal based on the prefix - '0x' indicates hexadecimal, '0' indicates octal, and all other values are decimal. Leading spaces, as determined by isspace(), are skipped. If b is 16, the string may be prefixed by '0x' and this will be skipped. The base may be any value from 2 to 36. If the value cannot be converted because it is too large, it will return LLONG_MAX or LLONG_MIN, depending on whether the overflowing value was positive or negative, and errno will be set to ERANGE.
EntryFunctionDescription
56unsigned long long strtoull(const char *s, char **e, int b);Returns the value of the string in s as an unsigned value, given in base b, storing the end of the conversion in pointer at e. This function is identical to strtoll, except that underflow cannot be reported, and an overflow is indicated by ULLONG_MAX.
EntryFunctionDescription
57long long imaxabs(long long i);Returns the absolute value of a 64bit value. Equivalent to llabs.
EntryFunctionDescription
58intmax_t imaxdiv(long long j, long long k);Divides an intmax_t value by a second intmax_t value. Equivalent to lldiv.
EntryFunctionDescription
59intmax_t strtoimax(const char *s, char **e, int b);Equivalent to strtoll.
60intmax_t strtouimax(const char *s, char **e, int b);Equivalent to strtoull.

Core library support functions

EntryFunctionDescription
61void __assert2(const char *message, const char *func, const char *file, int line);Displays an error to stderr in response to an assertion, and then calls abort(). Never returns.
EntryFunctionDescription
62void _Exit(int status);Terminates the program immediately, without calling the 'atexit' functions. This may mean under a C++ environment that destructors are not invoked. File descriptors opened by the standard stream functions will be closed.

Extended floating point functions

The following entries are provided. Their behaviour is as specified by C99 for the functions of those names, with the 'f' suffix indicating the float variant.

EntryFunctionDescription
63acosf
64asinf
65atanf
66atan2f
67cosf
68sinf
69tanf
70acosh
71acoshf
72asinh
73asinhf
74atanh
75atanhf
76expf
77exp2
78exp2f
79expm1
80expm1f
81frexpf
82ilogb
83ilogbf
84ldexpf
85logf
86log10f
87log1p
88log1pf
89log2
90log2f
91logb
92logbf
93modff
94fmodf
95scalbn
96scalbnf
97scalbln
98scalblnf
99cbrt
100cbrtf
101powf
102sqrtf
103erf
104erff
105erfc
106erfcf
107lgamma
108lgammaf
109tgamma
110tgammaf
111nexttoward
112nexttowardf
113fmaf