aboutsummaryrefslogtreecommitdiffstats
path: root/ext/mandel/mandel.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:32 +0000
commit9c5b1986a36c7a700b4c76817e35aa874ba7907c (patch)
tree5951a3d3d9a696af427384e6128c42ec2256e687 /ext/mandel/mandel.c
parentedf2e9b7c75d2fff380f03c9ae279e53fe05ab59 (diff)
downloadruby-9c5b1986a36c7a700b4c76817e35aa874ba7907c.tar.gz
Initial revision
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/mandel/mandel.c')
-rw-r--r--ext/mandel/mandel.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/ext/mandel/mandel.c b/ext/mandel/mandel.c
new file mode 100644
index 0000000000..359c0756da
--- /dev/null
+++ b/ext/mandel/mandel.c
@@ -0,0 +1,59 @@
+/************************************************
+
+ mandel.c -
+
+ $Author$
+
+************************************************/
+
+#include "ruby.h"
+#include "math.h"
+
+static VALUE
+mandel(self, re, im, max)
+ VALUE self;
+ VALUE re;
+ VALUE im;
+ VALUE max;
+{
+ double real, image;
+ double z_real, z_image;
+ double tmp_real;
+ int maximum;
+ int i;
+
+ Check_Type(re, T_FLOAT);
+ Check_Type(im, T_FLOAT);
+ Check_Type(max, T_FIXNUM);
+
+ real = RFLOAT(re)->value;
+ image = RFLOAT(im)->value;
+ maximum = FIX2INT(max);
+
+ /***
+ z = c = Complex(re, im)
+ for i in 0 .. $max_deapth
+ z = (z * z) + c
+ break if z.abs > 2
+ end
+ return i
+ ***/
+
+ z_real = real;
+ z_image = image;
+ for (i = 0; i < maximum; i++) {
+ tmp_real = ((z_real * z_real) - (z_image * z_image)) + real;
+ z_image = ((z_real * z_image) + (z_image * z_real)) + image;
+ z_real = tmp_real;
+ if ( ((z_real * z_real) + (z_image * z_image)) > 4.0 ) {
+ break;
+ }
+ }
+ return INT2FIX(i);
+}
+
+Init_mandel()
+{
+ VALUE mMandel = rb_define_module("Mandel");
+ rb_define_module_function(mMandel, "mandel", mandel, 3);
+}