Questions tagged [infinity]

Infinity is a specific floating point value that is always larger than any other floating point value. It may arise as a result of division by zero, arithmetic overflow and other exceptional operations. Infinity is different from the maximal still valid floating point value that the certain data type can hold. IEEE 754 floating point standard allows both positive and negative infinity values.

Infinity is a specific floating point value that is always larger than any other floating point value. It may arise as a result of division by zero, arithmetic overflow and other exceptional operations. IEEE 754 floating point standard allows both positive and negative infinity values.

Infinity is different from the maximal still valid floating point value that the certain data type can hold. This value is still smaller than the infinity.

Some programming languages allow to specify the infinity in the code explicitly. For instance, the Java code

    double [] values = ...
    double min = Double.POSITIVE_INFINITY;

    for (double x: values) 
      if (x < min) min = x;

can be used to obtain the minimal value in the array that only contains usual, valid floating point values.

475 questions
14
votes
3 answers

Infinity is some number in javascript?

alert(1/0) alerts Infinity and alert(1/-0) alerts -Infinity. alert(-1/-0) alerts Infinity, as I could expect when doing some operations with real numbers. I can't say that infinity is a measurable value. Does javascript think it is some number?
nicael
  • 18,550
  • 13
  • 57
  • 90
13
votes
4 answers

O-notation, O(∞) = O(1)?

So a quick thought; Could one argue that O(∞) is actually O(1)? I mean it isn't depend on input size? So in some way its, constant, even though it infinity. Or is the only 'correct' way to express it O(∞)?
Poul Walker
  • 131
  • 1
  • 3
13
votes
2 answers

Represent infinity as an integer in Python 2.7

I am wondering how to define inf and -inf as an int in Python 2.7. I tried and it seems inf and -inf only work as a float. a = float('-inf') # works b = float('inf') # works c = int('-inf') # compile error, ValueError: invalid…
Lin Ma
  • 9,739
  • 32
  • 105
  • 175
13
votes
1 answer

What is the best way to check for infinity in a Perl module?

In one of my modules, I have to deal with the concept of infinity. To date, I have been using 9**9**9 as positive infinity, and this seems to work well, is fast, and seems to be what perl's internals use as infinity. However, things get a bit…
Eric Strom
  • 39,821
  • 2
  • 80
  • 152
13
votes
6 answers

What do these three special floating-point values mean: positive infinity, negative infinity, NaN?

How can we use them in our codes, and what will cause NaN(not a number)?
Johanna
  • 27,036
  • 42
  • 89
  • 117
12
votes
3 answers

Is there any way to programmatically set the camera focus off an iOS device to infinity?

I am creating an app that locks the camera focus for video recording purposes. I want to lock the focus to infinity without having the user manually adjust the focus. Is this possible? Thanks!
jsrivo
  • 167
  • 1
  • 1
  • 8
12
votes
2 answers

Java: Printing out an object for debugging

I would like an easy way to print out a java object, or to say it another way, serialize an object as a string. I would like to see the values of all variables contained within the object, and if there are more objects (like a list or whatever) it…
Muhd
  • 24,305
  • 22
  • 61
  • 78
12
votes
5 answers

Infinity in Fortran

What is the safest way to set a variable to +Infinity in Fortran? At the moment I am using: program test implicit none print *,infinity() contains real function infinity() implicit none real :: x x = huge(1.) infinity =…
astrofrog
  • 32,883
  • 32
  • 90
  • 131
12
votes
2 answers

How are Inf and NaN implemented?

As mathematical concepts, I am well aware of what inf and nan actually are. But what I am really interested in is how they are implemented in programming languages. In python, I can use inf and nan in arithmetic and conditional expressions, like…
cs95
  • 379,657
  • 97
  • 704
  • 746
11
votes
9 answers

Multiple levels of infinity

Some programmers don't see much relevance in theoretical CS classes (especially my students). Here is something I find very relevant. Let me build it up in pieces for those that haven't seen it before... A) Programming problems can be reworded to be…
RAL
  • 917
  • 8
  • 19
11
votes
2 answers

Non-integer inhabitants of integers in Haskell

Peano natural numbers in Haskell defined as data Peano = Zero | Succ Peano are quite strange beasts: besides plain naturals and bottom values, there is an "infinite integer" inf = Succ inf among them. Are there any other inhabitants of the Peano…
nponeccop
  • 13,527
  • 1
  • 44
  • 106
11
votes
2 answers

When do we need to use float.PositiveInfinity and float.NegativeInfinity?

When do we need to use the Infinity values, kindly add a real-world sample if available.
Homam
  • 23,263
  • 32
  • 111
  • 187
10
votes
3 answers

Can division by non-zero still create a nan / infinity

I have a number which might be zeros. I divide by that number so I want to test if it's zero to prevent NaN's and infinitys. Is it possible that I still create NaNs / infinity because of rounding errors within the division? double x; // might be…
ruhig brauner
  • 943
  • 1
  • 13
  • 35
10
votes
2 answers

R: can range(data.frame) exclude infinite values?

I am trying to find the range of a data frame with infinite values: > f <- data.frame(x=c(1,2),y=c(3,Inf)) > range(f) [1] 1 Inf > range(f,finite=TRUE) Error in FUN(X[[2L]], ...) : only defined on a data frame with all numeric variables Calls:…
sds
  • 58,617
  • 29
  • 161
  • 278
10
votes
3 answers

representing infinity and NAN independent of implementation

Is there an implementation independent way of representing infinity or not a number (NAN) in Common Lisp? It would need to be a double float, and have both positive and negative values. In SBCL, the results of (apropos…
user2862490