Browse Source

Fixed print_int for negative numbers

main
Ludovic 'Archivist' Lagouardette 2 months ago
parent
commit
5c89f464f8
1 changed files with 26 additions and 21 deletions
  1. +26
    -21
      lib.c

+ 26
- 21
lib.c View File

@ -1950,27 +1950,32 @@ static void jump_if(struct context* ctx) {
}
static void print_int(struct context* ctx) {
struct ink_routine* currentRoutine;
struct elem a;
char* n;
char* str;
currentRoutine = ctx->routines + ctx->routine_current;
#ifndef NOEXTRACHECKS
if(currentRoutine->top < 1 || currentRoutine->stack[currentRoutine->top-1].type != INK_INTEGER) {
currentRoutine->panic = -1;
return;
}
#endif
a = currentRoutine->stack[currentRoutine->top-1];
ink_pop(ctx);
n = ink_itoa(ctx, a.value);
str = n;
while (*str) {
ctx->putchar(ctx, *str);
++str;
}
ctx->free(ctx, n);
n = NULL;
struct ink_routine* currentRoutine;
struct elem a;
char* n;
char* str;
currentRoutine = ctx->routines + ctx->routine_current;
#ifndef NOEXTRACHECKS
if(currentRoutine->top < 1 || currentRoutine->stack[currentRoutine->top-1].type != INK_INTEGER) {
currentRoutine->panic = -1;
return;
}
#endif
a = currentRoutine->stack[currentRoutine->top-1];
ink_pop(ctx);
if(a.value < 0) {
ctx->putchar(ctx, '-');
n = ink_itoa(ctx, -a.value);
} else {
n = ink_itoa(ctx, a.value);
}
str = n;
while (*str) {
ctx->putchar(ctx, *str);
++str;
}
ctx->free(ctx, n);
n = NULL;
}
static void print_as_utf8(struct context* ctx) {

Loading…
Cancel
Save