27 lines
484 B
C
27 lines
484 B
C
#include "print.h"
|
|
|
|
#include <assert.h>
|
|
|
|
size_t print(am_t *am, char *buffer, size_t buffer_size)
|
|
{
|
|
assert(am->val->is_atom);
|
|
assert(am->val->atom.type == ATOM_TYPE_INTEGER);
|
|
|
|
int64_t value = am->val->atom.integer;
|
|
int divisor = 10;
|
|
while (divisor <= value)
|
|
divisor *= 10;
|
|
|
|
size_t i = 0;
|
|
do {
|
|
divisor /= 10;
|
|
const int digit = value / divisor;
|
|
value = value % divisor;
|
|
|
|
assert(i < buffer_size);
|
|
buffer[i++] = '0' + (char)digit;
|
|
} while (divisor > 1);
|
|
|
|
return i;
|
|
}
|