00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "ruby.h"
00014
00015 VALUE rb_mPrecision;
00016
00017 static ID prc_pr, prc_if;
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 static VALUE
00035 prec_prec(x, klass)
00036 VALUE x, klass;
00037 {
00038 return rb_funcall(klass, prc_if, 1, x);
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 static VALUE
00050 prec_prec_i(x)
00051 VALUE x;
00052 {
00053 VALUE klass = rb_cInteger;
00054
00055 return rb_funcall(x, prc_pr, 1, klass);
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 static VALUE
00067 prec_prec_f(x)
00068 VALUE x;
00069 {
00070 VALUE klass = rb_cFloat;
00071
00072 return rb_funcall(x, prc_pr, 1, klass);
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 static VALUE
00089 prec_induced_from(module, x)
00090 VALUE module, x;
00091 {
00092 rb_raise(rb_eTypeError, "undefined conversion from %s into %s",
00093 rb_obj_classname(x), rb_class2name(module));
00094 return Qnil;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 static VALUE
00107 prec_included(module, include)
00108 VALUE module, include;
00109 {
00110 switch (TYPE(include)) {
00111 case T_CLASS:
00112 case T_MODULE:
00113 break;
00114 default:
00115 Check_Type(include, T_CLASS);
00116 break;
00117 }
00118 rb_define_singleton_method(include, "induced_from", prec_induced_from, 1);
00119 return module;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 void
00131 Init_Precision()
00132 {
00133 rb_mPrecision = rb_define_module("Precision");
00134 rb_define_singleton_method(rb_mPrecision, "included", prec_included, 1);
00135 rb_define_method(rb_mPrecision, "prec", prec_prec, 1);
00136 rb_define_method(rb_mPrecision, "prec_i", prec_prec_i, 0);
00137 rb_define_method(rb_mPrecision, "prec_f", prec_prec_f, 0);
00138
00139 prc_pr = rb_intern("prec");
00140 prc_if = rb_intern("induced_from");
00141 }
00142