385 } |
384 } |
386 |
385 |
387 LongInt fpcrtl_random(LongInt l) { |
386 LongInt fpcrtl_random(LongInt l) { |
388 // random(0) is undefined in docs but effectively returns 0 in free pascal |
387 // random(0) is undefined in docs but effectively returns 0 in free pascal |
389 if (l == 0) { |
388 if (l == 0) { |
390 printf("WARNING: random(0) called!\n"); |
389 //printf("WARNING: random(0) called!\n"); |
391 return 0; |
390 return 0; |
392 } |
391 } |
393 return (LongInt) (rand() / (double) RAND_MAX * l); |
392 return (LongInt) (rand() / (double) RAND_MAX * l); |
394 } |
393 } |
395 |
394 |
396 void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) { |
395 void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) { |
397 sprintf(s->str, "%f", x); |
396 s->len = sprintf(s->str, "%f", x); |
398 s->len = strlen(s->str); |
|
399 } |
397 } |
400 void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) { |
398 void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) { |
401 sprintf(s->str, "%f", x); |
399 s->len = sprintf(s->str, "%f", x); |
402 s->len = strlen(s->str); |
|
403 } |
400 } |
404 void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) { |
401 void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) { |
405 sprintf(s->str, "%u", x); |
402 s->len = sprintf(s->str, "%u", x); |
406 s->len = strlen(s->str); |
|
407 } |
403 } |
408 void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) { |
404 void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) { |
409 sprintf(s->str, "%d", x); |
405 s->len = sprintf(s->str, "%d", x); |
410 s->len = strlen(s->str); |
|
411 } |
406 } |
412 void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) { |
407 void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) { |
413 sprintf(s->str, "%u", x); |
408 s->len = sprintf(s->str, "%u", x); |
414 s->len = strlen(s->str); |
|
415 } |
409 } |
416 void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) { |
410 void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) { |
417 sprintf(s->str, "%d", x); |
411 s->len = sprintf(s->str, "%d", x); |
418 s->len = strlen(s->str); |
|
419 } |
412 } |
420 void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) { |
413 void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) { |
421 sprintf(s->str, "%u", x); |
414 s->len = sprintf(s->str, "%u", x); |
422 s->len = strlen(s->str); |
|
423 } |
415 } |
424 void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) { |
416 void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) { |
425 sprintf(s->str, "%d", x); |
417 s->len = sprintf(s->str, "%d", x); |
426 s->len = strlen(s->str); |
|
427 } |
418 } |
428 void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) { |
419 void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) { |
429 sprintf(s->str, "%llu", x); |
420 s->len = sprintf(s->str, "%llu", x); |
430 s->len = strlen(s->str); |
|
431 } |
421 } |
432 void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) { |
422 void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) { |
433 sprintf(s->str, "%lld", x); |
423 s->len = sprintf(s->str, "%lld", x); |
434 s->len = strlen(s->str); |
|
435 } |
424 } |
436 |
425 |
437 /* |
426 /* |
438 * XXX No protection currently! |
427 * XXX No protection currently! |
439 */ |
428 */ |