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)
  "#ifndef \#{name}_HEADER\n#define \#{name}_HEADER\n\n// Standard Libraries\n\#{ CAS::C_PLUGIN::C_STD_LIBRARIES.map { |e| \"#include <\#{e}>\" }.join(\"\\n\") }\n\n// Local Libraries\n\#{ CAS::C_PLUGIN::C_LOCAL_LIBRARIES.map { |e| \"#include <\#{e}>\" }.join(\"\\n\") }\n\n// Definitions\n\#{ CAS::C_PLUGIN::C_DEFINES.map { |k, v| \"#define \#{k} \#{v}\" }.join(\"\\n\") }\n\n// Function\ndouble \#{name}(\#{ op.args.map { |x| \"double \#{x.name}\"}.join(\", \") });\n\n#endif // \#{name}_HEADER\n  TO_HEADER\nend\n"

.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)
  "#include \"\#{name}.h\"\n\ndouble \#{name}(\#{ op.args.map { |x| \"double \#{x.name}\"}.join(\", \") }) {\n  return \#{op.to_c};\n}\n  TO_SOURCE\nend\n"