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
771
votes
13 answers

How can I represent an infinite number in Python?

How can I represent an infinite number in python? No matter which number you enter in the program, no number should be greater than this representation of infinity.
ssierral
  • 8,537
  • 6
  • 26
  • 44
189
votes
9 answers

Infinity symbol with HTML

How can I display an infinity symbol (like the one in the picture) using HTML?
user94154
  • 16,176
  • 20
  • 77
  • 116
184
votes
5 answers

Python Infinity - Any caveats?

So Python has positive and negative infinity: float("inf"), float("-inf") This just seems like the type of feature that has to have some caveat. Is there anything I should be aware of?
Casebash
  • 114,675
  • 90
  • 247
  • 350
178
votes
11 answers

How to implement infinity in Java?

Does Java have anything to represent infinity for every numerical data type? How is it implemented such that I can do mathematical operations with it? E.g. int myInf = infinity; //However it is done myInf + 5; //returns infinity myInf*(-1);…
user1753100
  • 1,909
  • 2
  • 14
  • 12
154
votes
3 answers

How to express infinity in Ruby?

Is there a keyword to express Infinity in Ruby?
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
148
votes
6 answers

Setting an int to Infinity in C++

I have an int a that needs to be equal to "infinity". This means that if int b = anyValue; a>b is always true. Is there any feature of C++ that could make this possible?
daniel gratzer
  • 52,833
  • 11
  • 94
  • 134
114
votes
8 answers

How do I check if a number evaluates to infinity?

I have a series of Javascript calculations that (only under IE) show Infinity depending on user choices. How does one stop the word Infinity appearing and for example, show 0.0 instead?
Homer_J
  • 3,277
  • 12
  • 45
  • 65
111
votes
10 answers

How to use nan and inf in C?

I have a numerical method that could return nan or inf if there was an error, and for testing purposed I'd like to temporarily force it to return nan or inf to ensure the situation is being handled correctly. Is there a reliable,…
Graphics Noob
  • 9,790
  • 11
  • 46
  • 44
102
votes
3 answers

Infinite integer in Python

Python 3 has float('inf') and Decimal('Infinity') but no int('inf'). So, why a number representing the infinite set of integers is missing in the language? Is int('inf') unreasonable?
Carlo Pires
  • 4,606
  • 7
  • 32
  • 32
99
votes
6 answers

How to find max value for Double and Float in Swift

Current learning Swift, there are ways to find max and min value for different kind of Integer like Int.max and Int.min. Is there a way to find max value for Double and Float? Moreover, which document should I refer for this kind of question? I am…
XY L
  • 25,431
  • 14
  • 84
  • 143
67
votes
3 answers

Replace -inf with zero value

I have an array: x = numpy.array([-inf, -inf, 37.49668579]) Is there a way to change the -inf values to just 0?
user1821176
  • 1,141
  • 2
  • 18
  • 29
64
votes
4 answers

In JavaScript, why does zero divided by zero return NaN, but any other divided by zero return Infinity?

It seems to me that the code console.log(1 / 0) should return NaN, but instead it returns Infinity. However this code: console.log(0 / 0) does return NaN. Can someone help me to understand the reasoning for this functionality? Not only does…
Bloodyaugust
  • 2,463
  • 8
  • 30
  • 46
55
votes
3 answers

Why is log(inf + inf j) equal to (inf + 0.785398 j), In C++/Python/NumPy?

I've been finding a strange behaviour of log functions in C++ and numpy about the behaviour of log function handling complex infinite numbers. Specifically, log(inf + inf * 1j) equals (inf + 0.785398j) when I expect it to be (inf + nan * 1j). When…
Firman
  • 928
  • 7
  • 15
54
votes
8 answers

Why are floating point infinities, unlike NaNs, equal?

Why doesn't infinity comparison follow the logic applied to NaNs? This code prints out false three times: double a = Double.NaN; double b = Double.NaN; System.out.println(a == b); // false System.out.println(a < b); // false System.out.println(a >…
jck
  • 669
  • 5
  • 9
52
votes
7 answers

How to make an integer larger than any other integer?

Note: while the accepted answer achieves the result I wanted, and @ecatmur answer provides a more comprehensive option, I feel it's very important to emphasize that my use case is a bad idea in the first place. This is explained very well in @Jason…
max
  • 49,282
  • 56
  • 208
  • 355
1
2 3
31 32