int enif_get_double(ErlNifEnv* env, ERL_NIF_TERM term, double* dp) { FloatDef f; if (is_not_float(term)) { return 0; } GET_DOUBLE(term, f); *dp = f.fd; return 1; }
BIF_RETTYPE trunc_1(BIF_ALIST_1) { Eterm res; FloatDef f; /* check arg */ if (is_not_float(BIF_ARG_1)) { if (is_integer(BIF_ARG_1)) BIF_RET(BIF_ARG_1); BIF_ERROR(BIF_P, BADARG); } /* get the float */ GET_DOUBLE(BIF_ARG_1, f); /* truncate it and return the resultant integer */ res = double_to_integer(BIF_P, (f.fd >= 0.0) ? floor(f.fd) : ceil(f.fd)); BIF_RET(res); }
BIF_RETTYPE round_1(BIF_ALIST_1) { Eterm res; FloatDef f; /* check arg */ if (is_not_float(BIF_ARG_1)) { if (is_integer(BIF_ARG_1)) BIF_RET(BIF_ARG_1); BIF_ERROR(BIF_P, BADARG); } /* get the float */ GET_DOUBLE(BIF_ARG_1, f); /* round it and return the resultant integer */ res = double_to_integer(BIF_P, (f.fd > 0.0) ? f.fd + 0.5 : f.fd - 0.5); BIF_RET(res); }