Forum: Ruby-dev [ruby-trunk - Feature #2968] 数値の正負を返すメソッド

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 yhara (Yutaka HARA) (Guest)
on 2012-10-27 17:09
(Received via mailing list)
Issue #2968 has been updated by yhara (Yutaka HARA).

Target version set to next minor

Feature #2968: 数値の正負を返すメソッド

Author: naruse (Yui NARUSE)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: core
Target version: next minor

 主たる想定用途は 0.0 と -0.0 を区別したいときです。
 これは、0.0 > -0.0 や 0.0 == -0.0 では知ることができません。
 とりあえず flo.to_s[0] == ?- で知ることができますが、これではあんまりです。

 * Numeric#positive? と Numeric#negative?
 * Numeric#sign -> 負で -1、正で 1
 * Numeric#sign? -> 負で true, 正で false (signbit(3) に習う)

This topic is locked and can not be replied to.