문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top