3

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?

johannes
  • 7,262
  • 5
  • 38
  • 57

1 Answers1

1

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.

Community
  • 1
  • 1
johannes
  • 7,262
  • 5
  • 38
  • 57