Permalink
Browse files

added abs method

  • Loading branch information...
1 parent 4cb8f62 commit 4f5d1cc80050c2eddcbb0967f9cb21eeaf66e1b1 @fogus fogus committed Oct 15, 2010
Showing with 13 additions and 0 deletions.
  1. +13 −0 core/number.c
View
@@ -135,8 +135,21 @@ static PN potion_num_is_float(Potion *P, PN cl, PN self) {
return PN_IS_DECIMAL(self) ? PN_TRUE : PN_FALSE;
}
+static PN potion_abs(Potion *P, PN cl, PN self) {
+ if (PN_IS_DECIMAL(self)) {
+ double d = PN_DBL(self);
+
+ if (d < 0.0)
+ return (PN) potion_real(P, -d);
+ else
+ return self;
+ }
+ return PN_NUM(abs(PN_INT(self)));
+}
+
void potion_num_init(Potion *P) {
PN num_vt = PN_VTABLE(PN_TNUMBER);
+ potion_method(num_vt, "abs", potion_abs, 0);
potion_method(num_vt, "+", potion_add, "value=N");
potion_method(num_vt, "-", potion_sub, "value=N");
potion_method(num_vt, "*", potion_mult, "value=N");

0 comments on commit 4f5d1cc

Please sign in to comment.