How to represent infinity in Java?
This article guides to you use and represent infinity in java. In mathematics, infinity which is symbolically represented by ∞ is used to represent a number that has no bounds. Is there a way to use inifinity in the same way to set ranges in a java program as well. Can it symbolically be represented in java as well?
Introduction
"Infinity (symbolically represented with ∞) comes from the Latin infinitas or "unboundedness." It refers to several distinct concepts – usually linked to the idea of "without end" – which arise in philosophy, mathematics, and theology.
In mathematics, "infinity" is often used in contexts where it is treated as if it were a number (i.e., it counts or measures things: "an infinite number of terms")" http://en.wikipedia.org/wiki/Infinity
How is infinity represented in Java?
In Java, the wrapper classes (Double and Float) that wrap the value of the primary types double and float each in an object contain static constants holding the value of infinity of its respective type.
There are two of types infinities:
- Negative Infinity (In mathematics, symbolically represented by -∞)
- Positive Infinity (In mathematics, symbolically represented by ∞)
Number Classes
Class Double and Float extend the class Number- "The abstract class Number is the superclass of classes BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short." see Java Docs
Double - Negative and Positive Infinities
- Double.NEGATIVE_INFINITY
A constant holding the negative infinity of type double.
- Double.POSITIVE_INFINITY
A constant holding the positive infinity of type double.
Float - Negative and Positive Infinities
- Float.NEGATIVE_INFINITY
A constant holding the negative infinity of type float .
- Float.POSITIVE_INFINITY
A constant holding the positive infinity of type float.
Examples
Consider some simple examples below
Using Negative Infinity:
In this example, the input is a number and and the number's validity should be checked by the given condition:
Condition for Validity: (-∞ <= x <= 20)
{
if( number >= Double.NEGATIVE_INFINITY && number <= 20 )
{
return true;
}
}
Using Positive Infinity:
In this example, the length of a StringThe String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Below are all the articles related to String. should only belong to only the specified range. The given range/restriction for the String is (1 <= x <= ∞)
{
int length = value.length();
if( length >= 1 && length <= Double.POSITIVE_INFINITY )
{
return true;
}
}
- Categories:








Comments
html characters in code
Hi,
seems some of your characters (i.e. '&') in the code section are incorrectly interpreted. I see "&&", whereas when I write
...
}
it seems to work. Thought you might want to know. Btw, I use Firefox 3.5.2.
/Kalle
Help
I am trying to write a program to try and solve this question:
1)1. Write a Java program that read a series of numbers (integer) until the user input “0”. This program will return:
a. Biggest number.
b. Smallest number.
I was hoping if you could point me in the right direction on how to write this code as its for a college project. Thanks
bnatey
توبيكات
توبيكات توبيكات
توبيكات اسلاميه
توبيكات اسلاميه
توبيكات حزينه
توبيكات حب
توبيكات رومانسيه
توبيكات اسماء
توبيكات اغاني
توبيكات منوعه
توبيكات مضحكه
توبيكات عتاب
توبيكات عتاب
توبيكات ساخره
توبيكات شعريه
توبيكات اجنبيه
توبيكات جديده
توبيكات بنات
توبيكات 2010
توبيكات اعياد
توبيكات عيد الاضحى
توبيكات مناسبات
توبيكات اعياد ميلاد
توبيكات رأس السنه
توبيكات كريسماس
توبيكات توبيكات
توبيكات كرة قدم
توبيكات كأس العالم
توبيكات مصر
توبيكات إلا رسول الله
توبيكات الاهلي
توبيكات الزمالك
توبيكات
توبيكات
توبيكات اسلاميه
توبيكات حزينه
توبيكات حب
توبيكات رومانسيه
توبيكات اسماء
توبيكات اغاني
توبيكات منوعه
توبيكات مضحكه
توبيكات عتاب
توبيكات ساخره
توبيكات شعريه
توبيكات اجنبيه
توبيكات نكت
توبيكات جوال
توبيكات سعوديه
توبيكات شخصيات فنيه
توبيكات ليلة العمر
توبيكات
توبيكات
توبيكات فلاش
توبيكات روعه
توبيكات رائعه
منتديات
دردشة
العاب
العاب بنات
شات
توبيكات مصريه
توبيكات قطريه
دليل مواقع
تحميل صور
مركز تحميل
برامج
كأس العالم
كأس العالم 2010
العاب
العاب بنات
منتدي
فيديو بنات
برامج
مركز رفع صور
شات
دليل المواقع العربيه
العاب
العاب
دليل مواقع
توبيكات
كتب
مقالات
صور
منتدى أجنبي
منتديات
Post new comment