summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <pks@pks.rocks>2018-04-17 17:59:55 +0200
committerPatrick Simianer <pks@pks.rocks>2018-04-17 17:59:55 +0200
commitf723db2eb2d3ec007afd184c98520581e6d0a3f1 (patch)
treec9d84bbe24d06b07cb711608b770c1862bab72f8
parentf44539de04b178f3a1b14960407ec683030f927a (diff)
inv
-rwxr-xr-xinv33
1 files changed, 33 insertions, 0 deletions
diff --git a/inv b/inv
new file mode 100755
index 0000000..50ad9cb
--- /dev/null
+++ b/inv
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+require 'trollop'
+
+def main
+ conf = Trollop::options do
+ opt :only_low, "inverse only for values < 1.0", :type => :bool, :default => false, :short => "-l"
+ opt :only_high, "inverse only for values > 1.0", :type => :bool, :default => false, :short => "-h"
+ end
+
+ while line = STDIN.gets
+ f = line.to_f
+
+ if conf[:only_low]
+ if f < 1
+ puts line.to_f**(-1)
+ else
+ puts line.to_f
+ end
+ elsif conf[:only_high]
+ if f > 1
+ puts line.to_f**(-1)
+ else
+ puts line.to_f
+ end
+ else
+ puts line.to_f**(-1)
+ end
+ end
+end
+
+main
+