perl11/potion

numeric compare in wrong integer context

rurban opened this issue · 2 comments

potion -e'x = 0.01 > 4, x print'
=> true

because the registers are compared in integer context.

we need to check the numeric type like this (dynamic version):

#define PN_VM_NUMCMP(cmp)                     \
  if (PN_IS_NUM(reg[op.a]) && PN_IS_NUM(reg[op.b])        \
    reg[op.a] = PN_BOOL(reg[op.a] cmp reg[op.b]);         \
  else                                    \
    reg[op.a] = PN_BOOL(PN_DBL(reg[op.a]) cmp PN_DBL(reg[op.b])); \

see branch numcmp

Fixes merged into master