summaryrefslogtreecommitdiff
path: root/inv
blob: b13443f3d964f63c416f845d599940bd77c87d8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env ruby

require 'optimist'

def main
  conf = Optimist::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