Project

General

Profile

Actions

Feature #10378

open

[PATCH 0/3] It's better (1 + 0i).real? return true

Added by gogotanaka (Kazuki Tanaka) about 10 years ago. Updated almost 7 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:65680]

Description

Right now, Complex#real? return false anytime.

I suppose #is_a?(Complex) is enough to check whether a object is Complex's object or not.
(I have to admire #real? is more useful than #is_a?(Complex))

But what we really want to know is whether a object whose class has Numeric as superclass is equal to real number or not.

Actually whichever is ok, modifying #real? or implementing as new method(e.g #real_num? ... :(

Anyway, I wanna method like that for Complex.

static VALUE
nucomp_real_p(VALUE self)
{
    get_dat1(self);
    if (rb_equal(dat->imag, INT2FIX(0))) {
        return Qtrue;
    }
    return Qfalse;
}

By the way, I can find two coding styles through ruby source code.

Which is prefer? it doesn't matter?

if(...)
    return ...
retrun ...

or

if(...) {
    return ...
}
retrun ...

Files

update_NEWS.patch (716 Bytes) update_NEWS.patch gogotanaka (Kazuki Tanaka), 10/26/2014 03:19 AM
add_tests.patch (848 Bytes) add_tests.patch gogotanaka (Kazuki Tanaka), 10/26/2014 03:19 AM
update_Complex#real_.patch (1.18 KB) update_Complex#real_.patch gogotanaka (Kazuki Tanaka), 10/26/2014 03:19 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #17631: `Numeric#real?` incorrectly returns true for `NaN` and `INFINITY`RejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0