Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Ruby Programming
Previous Page Home Next Page
class Float
Parent: Numeric
Version: 1.6


Arithmetic operations <=> ceil finite? floor infinite? nan? round to_f to_i to_s

Float objects represent real numbers using the native architecture's double-precision floating point representation.

instance methods
Arithmetic operations

Performs various arithmetic operations on flt.

flt + aNumeric Addition
flt -- aNumeric Subtraction
flt * aNumeric Multiplication
flt / aNumeric Division
flt % aNumeric Modulo
flt ** aNumeric Exponentiation

<=> flt <=> aNumeric -> -1, 0, +1

Returns -1, 0, or +1 depending on whether flt is less than, equal to, or greater than aNumeric. This is the basis for the tests in Comparable.

ceil flt.ceil -> anInteger

Returns the smallest Integer greater than or equal to flt.

1.2.ceil 2
2.0.ceil 2
(-1.2).ceil -1
(-2.0).ceil -2

finite? flt.finite? -> true or false

Returns true if flt is a valid IEEE floating point number (it is not infinite, and nan? is false).

floor flt.floor -> anInteger

Returns the largest integer less than or equal to flt.

1.2.floor 1
2.0.floor 2
(-1.2).floor -2
(-2.0).floor -2

infinite? flt.infinite? -> nil, -1, +1

Returns nil, -1, or +1 depending on whether flt is finite, -infinity, or +infinity.

(0.0).infinite? nil
(-1.0/0.0).infinite? -1
(+1.0/0.0).infinite? 1

nan? flt.nan? -> true or false

Returns true if flt is an invalid IEEE floating point number.

a = -1.0 -1.0
a.nan? false
a = Math.log(a) NaN
a.nan? true

round flt.round -> anInteger

Rounds flt to the nearest integer. Equivalent to:

def round
  return floor(self+0.5) if self > 0.0
  return ceil(self-0.5)  if self < 0.0
  return 0.0

1.5.round 2
(-1.5).round -2

to_f flt.to_f -> flt

Returns flt.

to_i flt.to_i -> anInteger

Returns flt truncated to an Integer.

to_s flt.to_s -> aString

Returns a string containing a representation of self. As well as a fixed or exponential form of the number, the call may return ``NaN'', ``Infinity'', and ``-Infinity''.

Ruby Programming
Previous Page Home Next Page

  Published under the terms of the Open Publication License Design by Interspire