C Package v0.1.0
The package is under active development and its API is not yet stable. Names, signatures, and behavior may change between releases, and this documentation will be updated to match.
Thin bindings to the platform C standard library for Rux programs.
Package: C
Source: github.com/rux-lang/Rux/tree/main/Packages/C
The package links the platform C library through #Link and exposes its functions directly — the math library (libm), standard I/O, the general utilities, and the time functions. Each entry is a 1:1 binding to the C function of the same name, so the authoritative behavior is the C standard and the linked reference on every page.
Requirements
- A target with a C standard library — every supported OS (BSD, Linux, macOS, Windows) ships one, selected automatically per target.
Each function follows the C calling convention and the C contract exactly: no argument checking, no errno decoding, and no memory management beyond what the C function itself does. Prefer the cross-platform packages (Math, Io, Memory) for portable application code, and reach for these bindings when you need the C library specifically.
Installation
rux add C
rux install
Then import the symbols you need:
import C::{ printf, malloc, free };
Types
| Type | Description |
|---|---|
time_t | Arithmetic type representing a calendar time. |
clock_t | Arithmetic type representing processor time. |
tm | Calendar time broken into its components. |
timespec | A time in seconds and nanoseconds. |
Math
| Function | Description |
|---|---|
acosf | Computes arc cosine. |
acos | Computes arc cosine. |
acoshf | Computes inverse hyperbolic cosine. |
acosh | Computes inverse hyperbolic cosine. |
asinf | Computes arc sine. |
asin | Computes arc sine. |
asinhf | Computes inverse hyperbolic sine. |
asinh | Computes inverse hyperbolic sine. |
atanf | Computes arc tangent. |
atan | Computes arc tangent. |
atan2f | Computes arc tangent, using signs to determine quadrants. |
atan2 | Computes arc tangent, using signs to determine quadrants. |
atanhf | Computes inverse hyperbolic tangent. |
atanh | Computes inverse hyperbolic tangent. |
cbrtf | Computes cube root. |
cbrt | Computes cube root. |
ceilf | Computes smallest integer not less than the given value. |
ceil | Computes smallest integer not less than the given value. |
copysignf | Copies the sign of a floating-point value. |
copysign | Copies the sign of a floating-point value. |
cosf | Computes cosine. |
cos | Computes cosine. |
coshf | Computes hyperbolic cosine. |
cosh | Computes hyperbolic cosine. |
erff | Computes error function. |
erf | Computes error function. |
erfcf | Computes complementary error function. |
erfc | Computes complementary error function. |
expf | Computes e raised to the given power. |
exp | Computes e raised to the given power. |
exp2f | Computes 2 raised to the given power. |
exp2 | Computes 2 raised to the given power. |
expm1f | Computes e raised to the given power, minus one. |
expm1 | Computes e raised to the given power, minus one. |
fabs | Computes the absolute value of a floating-point value. |
fdimf | Computes positive difference of two floating-point values. |
fdim | Computes positive difference of two floating-point values. |
floorf | Computes largest integer not greater than the given value. |
floor | Computes largest integer not greater than the given value. |
fmaf | Computes fused multiply-add. |
fma | Computes fused multiply-add. |
fmaxf | Computes larger of two floating-point values. |
fmax | Computes larger of two floating-point values. |
fminf | Computes smaller of two floating-point values. |
fmin | Computes smaller of two floating-point values. |
fmodf | Computes remainder of the floating-point division operation. |
fmod | Computes remainder of the floating-point division operation. |
frexp | Decomposes a number into significand and a power of two. |
hypot | Computes square root of the sum of the squares of two given numbers. |
ilogbf | Extracts exponent of the number. |
ilogb | Extracts exponent of the number. |
ldexp | Multiplies a number by 2 raised to an integer power. |
lgammaf | Computes natural logarithm of the absolute value of the gamma function. |
lgamma | Computes natural logarithm of the absolute value of the gamma function. |
llrintf | Rounds to nearest integer using current rounding mode. |
llrint | Rounds to nearest integer using current rounding mode. |
llroundf | Rounds to nearest integer, rounding away from zero in halfway cases. |
llround | Rounds to nearest integer, rounding away from zero in halfway cases. |
logf | Computes natural (base e) logarithm. |
log | Computes natural (base e) logarithm. |
log10f | Computes common (base 10) logarithm. |
log10 | Computes common (base 10) logarithm. |
log1pf | Computes natural logarithm of 1 plus the given number. |
log1p | Computes natural logarithm of 1 plus the given number. |
log2f | Computes base 2 logarithm. |
log2 | Computes base 2 logarithm. |
logbf | Extracts exponent of the number. |
logb | Extracts exponent of the number. |
lrintf | Rounds to nearest integer using current rounding mode. |
lrint | Rounds to nearest integer using current rounding mode. |
lroundf | Rounds to nearest integer, rounding away from zero in halfway cases. |
lround | Rounds to nearest integer, rounding away from zero in halfway cases. |
modff | Decomposes a number into integer and fractional parts. |
modf | Decomposes a number into integer and fractional parts. |
nanf | Generates a quiet NaN. |
nan | Generates a quiet NaN. |
nearbyintf | Rounds to nearest integer using current rounding mode without raising the inexact exception. |
nearbyint | Rounds to nearest integer using current rounding mode without raising the inexact exception. |
nextafterf | Determines next representable floating-point value toward the given value. |
nextafter | Determines next representable floating-point value toward the given value. |
powf | Computes a number raised to the given power. |
pow | Computes a number raised to the given power. |
remainderf | Computes signed remainder of the floating-point division operation. |
remainder | Computes signed remainder of the floating-point division operation. |
remquof | Computes signed remainder as well as the three last bits of the division operation. |
remquo | Computes signed remainder as well as the three last bits of the division operation. |
rintf | Rounds to nearest integer using current rounding mode. |
rint | Rounds to nearest integer using current rounding mode. |
roundf | Rounds to nearest integer, rounding away from zero in halfway cases. |
round | Rounds to nearest integer, rounding away from zero in halfway cases. |
scalbnf | Multiplies a number by FLT_RADIX raised to an integer power. |
scalbn | Multiplies a number by FLT_RADIX raised to an integer power. |
sinf | Computes sine. |
sin | Computes sine. |
sinhf | Computes hyperbolic sine. |
sinh | Computes hyperbolic sine. |
sqrtf | Computes square root. |
sqrt | Computes square root. |
tanf | Computes tangent. |
tan | Computes tangent. |
tanhf | Computes hyperbolic tangent. |
tanh | Computes hyperbolic tangent. |
tgammaf | Computes gamma function. |
tgamma | Computes gamma function. |
truncf | Rounds to nearest integer not greater in magnitude than the given value. |
trunc | Rounds to nearest integer not greater in magnitude than the given value. |
Standard I/O
| Function | Description |
|---|---|
clearerr | Clears the end-of-file and error indicators for the given stream. |
fclose | Closes the given file stream. |
feof | Checks if the end-of-file indicator is set for the given stream. |
ferror | Checks if the error indicator is set for the given stream. |
fflush | Writes any unwritten data from the stream's buffer to the file. |
fgetc | Reads the next character from the given stream. |
fgetpos | Gets the current file position of the stream. |
fgets | Reads at most count-1 characters from the stream into a string. |
fopen | Opens a file indicated by filename with the given mode. |
fprintf | Prints formatted output to a file stream. |
fputc | Writes a character to the given stream. |
fputs | Writes a string to the given stream. |
fread | Reads up to count objects of the given size from the stream into a buffer. |
freopen | Reopens a stream with a different file or mode. |
fscanf | Reads formatted input from a file stream. |
fseek | Sets the file position indicator for the stream. |
fsetpos | Sets the file position of the stream to the given position. |
ftell | Returns the current file position of the stream. |
fwrite | Writes count objects of the given size from a buffer to the stream. |
getc | Reads the next character from the given stream. |
getchar | Reads the next character from stdin. |
perror | Prints an error message describing the last error to stderr. |
printf | Prints formatted output to stdout. |
putc | Writes a character to the given stream. |
putchar | Writes a character to stdout. |
puts | Writes a string followed by a newline to stdout. |
remove | Deletes the file identified by the given path. |
rename | Renames a file, moving it if necessary. |
rewind | Moves the file position indicator to the beginning of the stream. |
scanf | Reads formatted input from stdin. |
setbuf | Sets the buffer to be used by the given stream. |
setvbuf | Sets the buffering mode and buffer to be used by the given stream. |
sprintf | Prints formatted output to a string. |
sscanf | Reads formatted input from a string. |
tmpfile | Creates and opens a temporary file with a unique name. |
tmpnam | Generates a unique filename that does not name an existing file. |
ungetc | Puts a character back into the given stream. |
Standard library
| Function | Description |
|---|---|
abort | Causes abnormal program termination without cleaning up. |
abs | Computes the absolute value of an integer value. |
atof | Converts a byte string to a floating point value. |
atoi | Converts a byte string to an integer value. |
atol | Converts a byte string to a long integer value. |
atoll | Converts a byte string to a long long integer value. |
calloc | Allocates memory for an array of num objects of size and zero-initializes it. |
exit | Causes normal program termination with cleanup. |
free | Deallocates the memory previously allocated by malloc, calloc or realloc. |
getenv | Returns the value of an environment variable. |
labs | Computes the absolute value of a long integer value. |
llabs | Computes the absolute value of a long long integer value. |
malloc | Allocates size bytes of uninitialized memory. |
rand | Returns a pseudo-random integer value between 0 and RAND_MAX. |
realloc | Changes the size of the memory block pointed to by ptr to size bytes. |
srand | Seeds the pseudo-random number generator used by rand. |
system | Calls the host environment's command processor. |
Time
| Function | Description |
|---|---|
asctime | Converts a tm object to a textual representation. |
clock | Returns the approximate processor time used by the program. |
ctime | Converts a time_t object to a textual representation. |
difftime | Computes the difference in seconds between two calendar times. |
gmtime | Converts a time_t object to calendar time expressed as UTC. |
localtime | Converts a time_t object to calendar time expressed as local time. |
mktime | Converts calendar time to a time_t object, normalizing the tm structure. |
strftime | Converts a tm object to a custom textual representation. |
time | Returns the current calendar time since the epoch. |