johannes
johannes

Reputation: 7272

How to express Infinity in C in a ruby extension

I want to do the equivalent of

::Infinity= 1.0/0

in a ruby extension which is written in C.

So far I have come up with

rb_const_set(rb_mKernel, rb_intern("Infinity"), rb_float_new(1.0/0));

which gives me a compiler warning due to division by zero. And

rb_const_set(rb_mKernel, rb_intern("Infinity"), rb_eval_string("1.0/0"));

which is ugly due to the usage of eval.

What is a clean proper solution to this?

Upvotes: 3

Views: 167

Answers (1)

johannes
johannes

Reputation: 7272

I found the answer in this question.

rb_const_set(rb_mKernel, rb_intern("Infinity"), rb_float_new(INFINITY));

There are no compiler warnings for this.

Upvotes: 1

Related Questions