Issue #10378 has been updated by gogo tanaka.


@Takeshi Nishimatsu san
Thank you for your comments and sharing good article.

From this article, your point-out might be right. I admit `Complex(x, 0.0)` is not truly real. 
And I suppose `-1.0-0.0i` not be `-1.0+0.0i` too.

Aside from that,  as I said `#is_a?(Complex)` or current `#real?` can be the way we check whether a number is truly real or not.
Actually whichever is ok, modifying #real? or implementing as new method.

What I want right now is checking whether a act as real. 

So lets run through a few scenarios (I'd better find more practical example... * (

```
c = (2.0 + 1.0i)

a1 = (-1.0+0.0i)
p c * a1

a2 = (-1.0-0.0i)
p c * a2

a3 = (-1.0+0i)
p c * a3

a4 = -1.0
p c * a4
```

a1~4 act as same. When I check a5 is also same, I have to write

```
a5.is_a?(Complex) && a5.imag.zero?
```

It's little bit diffuse.

Thanks.

----------------------------------------
Feature #10378: [PATCH 0/3] It's better (1 + 0i).real? return true
https://bugs.ruby-lang.org/issues/10378#change-49686

* Author: gogo tanaka
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: current: 2.2.0
----------------------------------------
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`.

```cpp
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?

```cpp
if(...)
    return ...
retrun ...
```

or 

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


---Files--------------------------------
update_NEWS.patch (716 Bytes)
add_tests.patch (848 Bytes)
update_Complex#real_.patch (1.18 KB)


-- 
https://bugs.ruby-lang.org/