24

I see there is a double.INFINITY but I can't see a way to say "int INFINITY". Which is interesting, because I see I can do some_integer.isInfinite.

What's a way to say int.INFINITY in Dart? Does that even make sense?

Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
  • 1
    what'd be the point? ints have fixed sizes they can't go past. allowing them to represent something outside their range would be rather counter-productive. – Marc B Sep 01 '15 at 18:29
  • 1
    @MarcB Ints in Dart don't have a fixed size. They are only "Limited by RAM" https://www.dartlang.org/articles/numeric-computation/ – Fox32 Sep 01 '15 at 19:10
  • 2
    I'm guessing that since the `isInfinite` method is inherited from `num`, and `int`s can be as big as RAM allows, it will always return `false` when called on an `int`. In other words, there is no "integer infinity" in Dart, and the method is only there because it gets inherited from `num`. – Tonio Sep 01 '15 at 19:55

1 Answers1

23

No. All Dart integers are finite. You can ask 42.isInfinite, but the answer is predictably false. If you check the code of the int class, you'll like find bool get isInfinite => false; somewhere.

The reason the getter is there at all is that it's defined on num, the superclass of int and double, and you can do many operation on numbers without knowing whether they are integers or doubles.

Marcel
  • 8,831
  • 4
  • 39
  • 50
lrn
  • 64,680
  • 7
  • 105
  • 121
  • Thanks! Should we update the dartdocs for int.isInfinite to say "always returns false" ? Right now, it says "True if the number is positive infinity or negative infinity; otherwise, false." – Seth Ladd Sep 01 '15 at 21:27
  • We could add something along the lines of "All integers are finite, only double has infinite values." as elaboration. – lrn Sep 02 '15 at 10:45