scicalc 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/scicalc.rb +27 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a568fd6c422acab82f44215f441b5ad449a8251f
4
+ data.tar.gz: 31f57928d9b2a57fff3c4bc6d24964e30396543e
5
+ SHA512:
6
+ metadata.gz: a5640646947954877abe9ec03cf0ac4f8e0c96200ea952c2ebcc0762a9a5b4e9cb775047e71dc61ebe91bed535dc88d725f494f45cce34cff0c1e073ef617345
7
+ data.tar.gz: fb240d4d65c7dbbbfee1a44d37751853fc1c82af3b608ccd6e0a7ff602a00314a62d252a4b72fa6fcab9445835928f92b23d07c732a674af3484a9b4a6874a44
@@ -0,0 +1,27 @@
1
+ class Calculator
2
+ def self.calculate(expression)
3
+ include Math
4
+ expression=expression.split
5
+ operands=[]
6
+ evaluation=[]
7
+ expression.each do |x|
8
+ case x
9
+ when /\d/
10
+ evaluation.push(x.to_f)
11
+ when "PI", "E"
12
+ evaluation.push(x=="PI" ? Math::PI : Math::E)
13
+ when "sin", "cos", "tan",
14
+ "asin", "acos", "atan",
15
+ "sinh", "cosh", "tanh",
16
+ "asinh", "acosh", "atanh", "atan2",
17
+ "exp", "log"
18
+ operands=evaluation.pop(1)
19
+ evaluation.push((Math.send(x, operands[0])))
20
+ when "-", "/", "*", "+", "**"
21
+ operands=evaluation.pop(2)
22
+ evaluation.push(operands[0].send(x, operands[1]))
23
+ end
24
+ end
25
+ puts evaluation
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scicalc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Laurent de la Garde de Saignes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple scientific calculator with basic operators, trigonometric &
14
+ transcendental functions
15
+ email: ldlgds.pro@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/scicalc.rb
21
+ homepage: http://rubygems.org/gems/scicalc
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.14.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A simple scientific calculator
45
+ test_files: []