From: NISHIMATSU Takeshi Date: 2003-04-04T04:25:43+09:00 Subject: [ruby-list:37516] Re: Math.erf, Math.erfc 西松です. 田中さん> これのことでしょうか? 拡張ライブラリですけど。 田中さん> ftp://ftp.ruby-lang.org/pub/ruby/contrib/extmath0.1.tar.gz それです, それです. % ruby --version ruby 1.6.8 (2002-12-24) [i686-linux] で, 次のようにしてインストールしたら動くようになりました. ありがとうございました. % tar zxvf extmath0.1.tar.gz % cd ext/extmath/ % patch < extmath-t-nissie-01.patch (下に添付しました quick hack なパッチです.) % ruby -rmkmf extconf.rb % make % su # make install --- 例 ------------------------------- #!/usr/bin/env ruby require 'extmath' p Math.sin(1.0) * Math.sin(1.0) p Math.cos(1) * Math.cos(1) p ExtMath.erf(0.5) p ExtMath.erfc(0.5) p ExtMath.erf(1) p ExtMath.erfc(1) include ExtMath p erf(1.5) p erfc(1.5) p erf(2) p erfc(2) p erf("2.1") p erfc("2.1") -------------------------------------- --- extmath-t-nissie-01.patch start ----------------------------------- --- extmath.c.orig Fri Apr 4 03:21:53 2003 +++ extmath.c Fri Apr 4 03:56:25 2003 @@ -16,14 +16,11 @@ /* these declarations are stolen from math.c */ -VALUE float_new(); -VALUE f_float(); - #define Need_Float(x) \ if (FIXNUM_P(x)) {\ - (x) = (struct RFloat*)float_new((double)FIX2INT(x));\ + (x) = (struct RFloat*)rb_float_new((double)FIX2INT(x));\ } else {\ - (x) = (struct RFloat*)f_float(x, x);\ + (x) = (struct RFloat*)rb_Float((VALUE)x);\ } #define Need_Float2(x,y) {\ @@ -36,26 +33,23 @@ #define NEWMATH1(rubyname,cname) \ static VALUE rubyname(VALUE obj, struct RFloat *x) {\ Need_Float(x);\ - return float_new(cname(x->value));\ + return rb_float_new(cname(x->value));\ } #define NEWMATH2FF(rubyname,cname) \ static VALUE rubyname(VALUE obj, struct RFloat *x, struct RFloat *y) {\ Need_Float2(x,y);\ - return float_new(cname(x->value,y->value));\ + return rb_float_new(cname(x->value,y->value));\ } #define NEWMATH2IF(rubyname,cname) \ static VALUE rubyname(VALUE obj, VALUE x, struct RFloat *y) {\ Need_Float(y);\ - return float_new(cname(NUM2INT(x),y->value));\ + return rb_float_new(cname(NUM2INT(x),y->value));\ } NEWMATH1(extm_lgamma,lgamma) -NEWMATH1(extm_asin,asin) -NEWMATH1(extm_acos,acos) -NEWMATH1(extm_atan,atan) NEWMATH1(extm_sinh,sinh) NEWMATH1(extm_cosh,cosh) NEWMATH1(extm_tanh,tanh) @@ -85,29 +79,26 @@ mExtMath = rb_define_module("ExtMath"); /* methods */ - rb_define_method(mExtMath,"lgamma",extm_lgamma,1); - rb_define_method(mExtMath,"asin",extm_asin,1); - rb_define_method(mExtMath,"acos",extm_acos,1); - rb_define_method(mExtMath,"atan",extm_atan,1); - rb_define_method(mExtMath,"sinh",extm_sinh,1); - rb_define_method(mExtMath,"cosh",extm_cosh,1); - rb_define_method(mExtMath,"tanh",extm_tanh,1); - rb_define_method(mExtMath,"asinh",extm_asinh,1); - rb_define_method(mExtMath,"acosh",extm_acosh,1); - rb_define_method(mExtMath,"atanh",extm_atanh,1); - rb_define_method(mExtMath,"ceil",extm_ceil,1); - rb_define_method(mExtMath,"floor",extm_floor,1); - rb_define_method(mExtMath,"fabs",extm_fabs,1); - rb_define_method(mExtMath,"cbrt",extm_cbrt,1); - rb_define_method(mExtMath,"erf",extm_erf,1); - rb_define_method(mExtMath,"erfc",extm_erfc,1); - rb_define_method(mExtMath,"j0",extm_j0,1); - rb_define_method(mExtMath,"j1",extm_j1,1); - rb_define_method(mExtMath,"jn",extm_jn,2); - rb_define_method(mExtMath,"y0",extm_y0,1); - rb_define_method(mExtMath,"y1",extm_y1,1); - rb_define_method(mExtMath,"yn",extm_yn,2); - rb_define_method(mExtMath,"expm1",extm_expm1,1); - rb_define_method(mExtMath,"log1p",extm_log1p,1); - rb_define_method(mExtMath,"hypot",extm_hypot,2); + rb_define_module_function(mExtMath,"lgamma",extm_lgamma,1); + rb_define_module_function(mExtMath,"sinh",extm_sinh,1); + rb_define_module_function(mExtMath,"cosh",extm_cosh,1); + rb_define_module_function(mExtMath,"tanh",extm_tanh,1); + rb_define_module_function(mExtMath,"asinh",extm_asinh,1); + rb_define_module_function(mExtMath,"acosh",extm_acosh,1); + rb_define_module_function(mExtMath,"atanh",extm_atanh,1); + rb_define_module_function(mExtMath,"ceil",extm_ceil,1); + rb_define_module_function(mExtMath,"floor",extm_floor,1); + rb_define_module_function(mExtMath,"fabs",extm_fabs,1); + rb_define_module_function(mExtMath,"cbrt",extm_cbrt,1); + rb_define_module_function(mExtMath,"erf",extm_erf,1); + rb_define_module_function(mExtMath,"erfc",extm_erfc,1); + rb_define_module_function(mExtMath,"j0",extm_j0,1); + rb_define_module_function(mExtMath,"j1",extm_j1,1); + rb_define_module_function(mExtMath,"jn",extm_jn,2); + rb_define_module_function(mExtMath,"y0",extm_y0,1); + rb_define_module_function(mExtMath,"y1",extm_y1,1); + rb_define_module_function(mExtMath,"yn",extm_yn,2); + rb_define_module_function(mExtMath,"expm1",extm_expm1,1); + rb_define_module_function(mExtMath,"log1p",extm_log1p,1); + rb_define_module_function(mExtMath,"hypot",extm_hypot,2); } --- extmath-t-nissie-01.patch end ------------------------------------- -- love && peace && free_software NISHIMATSU Takeshi t-nissie@imr.edu OR t-nissie@imr.tohoku.ac.jp 西松 毅