]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
math: ruby wants leading 0s to floating points numbers
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 1 Feb 2012 14:24:31 +0000 (15:24 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 1 Feb 2012 14:24:31 +0000 (15:24 +0100)
data/rbot/plugins/math.rb

index 081c9c042378cf761c5670e5df82dc34df3f6238..a6baa7090bb014b737776abbbd85d49906fb41b0 100644 (file)
@@ -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