summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2012-02-01 15:24:31 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2012-02-01 15:24:31 +0100
commitfd7b5cc1b0a07dcb61bf09db0c9d94946c7583fe (patch)
tree3bd023edfbb7a888eceed8f6673647f5c3e4e231 /data/rbot/plugins
parent7993226963ede0c50da4d32d2ba877c97736ad5c (diff)
math: ruby wants leading 0s to floating points numbers
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/math.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/data/rbot/plugins/math.rb b/data/rbot/plugins/math.rb
index 081c9c04..a6baa709 100644
--- a/data/rbot/plugins/math.rb
+++ b/data/rbot/plugins/math.rb
@@ -39,6 +39,11 @@ class MathPlugin < Plugin
expr.gsub!(/\b#{k}\b/, v)
}
+ # ruby doesn't like floating-point values without a 0
+ # in front of them, so find any non-digit followed by
+ # a .<digits> and insert a 0 before the .
+ expr.gsub!(/(\D|^)(\.\d+)/,'\10\2')
+
while expr =~ /(exp ([\w\d]+))/
exp = $1
val = Math.exp($2).to_s