Fixed the code style in *.c files to two spaces indentation and add a linter named funstx to Fun. (0.39.0)
This commit is contained in:
parent
33001a7ad2
commit
03b2532474
237 changed files with 17550 additions and 13911 deletions
|
|
@ -10,36 +10,36 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* @file sqrt.c
|
||||
* @file sqrt.c
|
||||
* @brief Implements the OP_SQRT opcode using C99 math.h sqrt().
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
case OP_SQRT: {
|
||||
Value v = pop_value(vm);
|
||||
if (v.type == VAL_INT || v.type == VAL_FLOAT) {
|
||||
double x = (v.type == VAL_FLOAT) ? v.d : (double)v.i;
|
||||
if (x < 0.0) {
|
||||
push_value(vm, make_float(NAN));
|
||||
} else {
|
||||
double r = sqrt(x);
|
||||
/* preserve int if exactly integral */
|
||||
if (r >= (double)INT64_MIN && r <= (double)INT64_MAX) {
|
||||
int64_t ii = (int64_t)r;
|
||||
if ((double)ii == r) {
|
||||
push_value(vm, make_int(ii));
|
||||
} else {
|
||||
push_value(vm, make_float(r));
|
||||
}
|
||||
} else {
|
||||
push_value(vm, make_float(r));
|
||||
}
|
||||
}
|
||||
free_value(v);
|
||||
Value v = pop_value(vm);
|
||||
if (v.type == VAL_INT || v.type == VAL_FLOAT) {
|
||||
double x = (v.type == VAL_FLOAT) ? v.d : (double)v.i;
|
||||
if (x < 0.0) {
|
||||
push_value(vm, make_float(NAN));
|
||||
} else {
|
||||
fprintf(stderr, "Runtime type error: SQRT expects number, got %s\n", value_type_name(v.type));
|
||||
exit(1);
|
||||
double r = sqrt(x);
|
||||
/* preserve int if exactly integral */
|
||||
if (r >= (double)INT64_MIN && r <= (double)INT64_MAX) {
|
||||
int64_t ii = (int64_t)r;
|
||||
if ((double)ii == r) {
|
||||
push_value(vm, make_int(ii));
|
||||
} else {
|
||||
push_value(vm, make_float(r));
|
||||
}
|
||||
} else {
|
||||
push_value(vm, make_float(r));
|
||||
}
|
||||
}
|
||||
break;
|
||||
free_value(v);
|
||||
} else {
|
||||
fprintf(stderr, "Runtime type error: SQRT expects number, got %s\n", value_type_name(v.type));
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue