How to Use Infinity in Java

Though it is impossible for a computer to literally represent the value of infinity in memory, the Java "double" and "float" data-type reserves two slots in its address range that are understood by the computer to refer to positive and negative infinity.

Instructions

    • 1

      Open your Java Integrated Development Environment (IDE).

    • 2

      Type the following to define a double (or float) with a value of positive or negative infinity:

      double pInfiniteDouble = Double.POSITIVE_INFINITY;

      double nInfiniteDouble = Double.NEGATIVE_INFINITY;

      float pInfiniteFloat = Float.POSITIVE_INFINITY;

      float nInfiniteFloat = Float.NEGATIVE_INFINITY;

    • 3

      Check to see if a double or float has a value of infinity using the "isInfinite()" method:

      pInfiniteDouble.isInfinite();

      nInfiniteDouble.isInfinite();

      pInfiniteFloat.isInfinite();

      nInfiniteFloat.isInfinite();

Tips & Warnings

  • There is one other odd value defined in the Double and Float data types: NotaNumber (NAN). It is accessed with "Double.NaN" or "Float.NaN."

  • Infinity and NaN are returned by some trigonometric and logarithmic functions in the Java math package.

Related Searches:

References

Comments

You May Also Like

  • How to Win Space Invaders

    Space Invaders was so popular in its original arcade release it caused a yen coin shortage in Japan. The arcade and Atari...

  • How to Get Rid of Java Update Notifications

    Java is a free program and browser plug-in from Sun Microsystems that many websites use for games, online chat rooms and other...

  • How to Do Inorder Traversal in Binary Tree in Java

    Java doesn't have a binary tree class, though it's simple to present a version of the data structure to do an inorder...

  • How to Type an Infinity Symbol

    The infinity symbol appears in certain types of mathematics and sciences and represents an number that has no end. If you create...

  • How to Program an Infiniti Remote

    Owners of Infiniti vehicles with power door locks and keyless entry systems can buy replacement remotes from an Infiniti dealer or online...

  • Java Games for a Nokia 6288

    The Java video game for the Nokia 6288 phone "Kung Fu Infinity" allows you to play as a burgeoning martial arts fighter...

  • Types of Infinities

    Intuition suggests there is only one kind of infinity. There are two kinds of infinity: Countable and uncountable. To compare infinities, one...

  • How to Get Blue Infinity in "RuneScape"

    Infinity robes are members-only magic armor. An infinity robes set consists of five pieces: top, bottom, hat, gloves and boots. You can...

  • Carrier Air Handler Specifications

    A Carrier air handler constitutes a basic component for forced-air heating unit or air conditioner systems. Many air handlers come as separate...

Related Ads

Featured