Module: CAS::C_PLUGIN

Defined in:
lib/Mr.CAS/c.rb

Constant Summary collapse

C_STD_LIBRARIES =
[
  "math.h"
]
C_LOCAL_LIBRARIES =
[ ]
C_DEFINES =
{
  "M_PI"       => Math::PI.to_s,
  "M_INFINITY" => "HUGE_VAL",
  "M_E"        => Math::E.to_s,
  "M_EPSILON"  => (1E-16).to_s
}

Class Method Summary collapse

Class Method Details

.write_header(op, name) ⇒ Object


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/Mr.CAS/c.rb', line 47

def self.write_header(op, name)
  <<-TO_HEADER
#ifndef #{name}_HEADER
#define #{name}_HEADER

// Standard Libraries
#{ CAS::C_PLUGIN::C_STD_LIBRARIES.map { |e| "#include <#{e}>" }.join("\n") }

// Local Libraries
#{ CAS::C_PLUGIN::C_LOCAL_LIBRARIES.map { |e| "#include <#{e}>" }.join("\n") }

// Definitions
#{ CAS::C_PLUGIN::C_DEFINES.map { |k, v| "#define #{k} #{v}" }.join("\n") }

// Function
double #{name}(#{ op.args.map { |x| "double #{x.name}"}.join(", ") });

#endif // #{name}_HEADER
  TO_HEADER
end

.write_source(op, name) ⇒ Object


68
69
70
71
72
73
74
75
76
# File 'lib/Mr.CAS/c.rb', line 68

def self.write_source(op, name)
  <<-TO_SOURCE
#include "#{name}.h"

double #{name}(#{ op.args.map { |x| "double #{x.name}"}.join(", ") }) {
  return #{op.to_c};
}
  TO_SOURCE
end