float types

E

elathan

Hello!

Shouldn't:

if (TYPE(arg1) == T_FLOAT)

be true when someone passes '42' (for example) and not '42.0'.

I understand TYPE(arg1) != T_FIXNUM when someone passes 42.0,
but I expect "42" to be a valid float argument.

I have foo(double i); and I check the passed arguments. I expect the
right ruby implementation to accept a foo(42) call.

Regards,
Elias
 
E

elathan

Quoting ts said:
e> if (TYPE(arg1) == T_FLOAT)

Write it

arg1 = rb_Float(arg1);

Actually I want to check the arguments' types before calling the
appopriate (overloaded) C++ function. So, I want a check that
'42' and '42.0' passes and a check that '42' only passes. So, if
I have:

foo (char *, double, double);
foo (double, int, int);

I can then call in ruby:

foo 42, 20, 20
foo 42.0, 20, 20
foo "bar", 10, 1.2

If this isn't supported by the Ruby API I will write my own C macro that
will return true if TYPE == T_FLOAT || TYPE == T_FIXNUM.

Regards,
Elias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top