Project

General

Profile

Actions

Feature #5310

open

Integral objects

Added by mrkn (Kenta Murata) over 12 years ago. Updated over 6 years ago.

Status:
Assigned
Target version:
-
[ruby-core:39498]

Description

I believe it is ambiguous what object can behave as an integral number.
I don't think the current use of Object#to_int isn't appropriate for this purpose.

The most understandable example is Float#to_int.
It should raise error for all float values because they always have uncertainty,
but it doesn't and returns an integral part of it.

I propose to change the use of Object#to_int for the next release of Ruby.
I recommend the following specification changes:

(1) Remove to_int method from Float and BigDecimal.
(2) Rational#to_int returns an Integer only if its denominator is 1. Otherwise, it raises an appropriate error.
(3) Complex#to_int returns the result of to_int of its real part only if its imaginary part is exactly zero (0.0 isn't exactly zero).

If anyone have another idea, please give me your comment.


Related issues 2 (1 open1 closed)

Related to Ruby master - Bug #1792: Fixnum#& 等が、Rational などを受けつけるClosedmrkn (Kenta Murata)07/19/2009Actions
Related to Ruby master - Feature #6973: Add an #integral? method to Numeric to test for whole-number valuesAssignedmrkn (Kenta Murata)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0