prec.c


DEFINITIONS

This source file includes following functions.
  1. prec_prec
  2. prec_prec_i
  3. prec_prec_f
  4. prec_induced_from
  5. prec_included
  6. Init_Precision


   1  /**********************************************************************
   2  
   3    prec.c -
   4  
   5    $Author: matz $
   6    $Date: 2002/04/18 08:46:18 $
   7    created at: Tue Jan 26 02:40:41 2000
   8  
   9    Copyright (C) 1993-2002 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      VALUE module, x;
  47  {
  48      rb_raise(rb_eTypeError, "undefined conversion from %s into %s",
  49              rb_class2name(CLASS_OF(x)), rb_class2name(module));
  50      return Qnil;                /* not reached */
  51  }
  52  
  53  static VALUE
  54  prec_included(module, include)
  55      VALUE module, include;
  56  {
  57      switch (TYPE(include)) {
  58        case T_CLASS:
  59        case T_MODULE:
  60         break;
  61        default:
  62         Check_Type(include, T_CLASS);
  63         break;
  64      }
  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, "included", prec_included, 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  }