master
Ondřej Hruška 3 years ago
parent 71dd84efee
commit 94ad9986cb
  1. 26
      src/fh_builtins_arith.c

@ -185,6 +185,31 @@ static enum fh_error w_greater(struct fh_thread_s *fh, const struct fh_word_s *w
return FH_OK;
}
static enum fh_error w_within(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
uint32_t test, low, high;
TRY(ds_pop(fh, &high));
TRY(ds_pop(fh, &low));
TRY(ds_pop(fh, &test));
// This should work, according to the spec:
// : WITHIN ( test low high -- flag ) OVER - >R - R> U< ;
// t l h | OVER
// t l h l | -
// t l (h-l) | >r
// t l | R:(h-l) | -
// (t-l) | R:(h-l) | R>
// (t-l) (h-l) | U<
// =within
bool within = 0; // TODO
TRY(ds_push(fh, TOBOOL(within)));
return FH_OK;
}
static enum fh_error w_u_less(struct fh_thread_s *fh, const struct fh_word_s *w)
{
@ -582,5 +607,6 @@ const struct name_and_handler fh_builtins_arith[] = {
{"fm/mod", w_fm_mod, 0, 0},
{"sm/rem", w_sm_rem, 0, 0},
{"um/mod", w_um_mod, 0, 0},
{"within", w_within, 0, 0},
{ /* end marker */ }
};

Loading…
Cancel
Save