Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (63 sloc) 1.621 kb
07bb9f2 1.4.0
matz authored
1 /************************************************
2
21d0b07 1.4.1
matz authored
3 prec.c -
07bb9f2 1.4.0
matz authored
4
5 $Author$
6 $Date$
7 created at: Tue Jan 26 02:40:41 1999
8
9 Copyright (C) 1993-1999 Yukihiro Matsumoto
10
11 *************************************************/
12
13 #include "ruby.h"
14
15 VALUE rb_mPrecision;
16
17 static ID prc_pr, prc_if;
18
19 static VALUE
20 prec_prec(x, klass)
21 VALUE x, klass;
22 {
23 return rb_funcall(klass, prc_if, 1, x);
24 }
25
26 static VALUE
27 prec_prec_i(x)
28 VALUE x;
29 {
30 VALUE klass = rb_cInteger;
31
32 return rb_funcall(x, prc_pr, 1, klass);
33 }
34
35 static VALUE
36 prec_prec_f(x)
37 VALUE x;
38 {
39 VALUE klass = rb_cFloat;
40
41 return rb_funcall(x, prc_pr, 1, klass);
42 }
43
44 static VALUE
45 prec_induced_from(module, x)
46
47 {
48 rb_raise(rb_eTypeError, "undefined conversion from %s into %s",
49 rb_class2name(CLASS_OF(x)), rb_class2name(module));
50 }
51
52 static VALUE
53 prec_append_features(module, include)
54 VALUE module, include;
55 {
56 switch (TYPE(include)) {
57 case T_CLASS:
58 case T_MODULE:
59 break;
60 default:
61 Check_Type(include, T_CLASS);
62 break;
63 }
64 rb_include_module(include, module);
65 rb_define_singleton_method(include, "induced_from", prec_induced_from, 1);
66 return module;
67 }
68
69
70 void
71 Init_Precision()
72 {
73 rb_mPrecision = rb_define_module("Precision");
74 rb_define_singleton_method(rb_mPrecision, "append_features", prec_append_features, 1);
75 rb_define_method(rb_mPrecision, "prec", prec_prec, 1);
76 rb_define_method(rb_mPrecision, "prec_i", prec_prec_i, 0);
77 rb_define_method(rb_mPrecision, "prec_f", prec_prec_f, 0);
78
79 prc_pr = rb_intern("prec");
80 prc_if = rb_intern("induced_from");
81 }
Something went wrong with that request. Please try again.