How to implement infinity in Java?

后端 未结 10 1328
别跟我提以往
别跟我提以往 2020-11-28 03:02

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.



        
10条回答
  •  悲哀的现实
    2020-11-28 03:40

    I'm not sure that Java has infinity for every numerical type but for some numerical data types the answer is positive:

    Float.POSITIVE_INFINITY
    Float.NEGATIVE_INFINITY
    

    or

    Double.POSITIVE_INFINITY
    Double.NEGATIVE_INFINITY
    

    Also you may find useful the following article which represents some mathematical operations involving +/- infinity: Java Floating-Point Number Intricacies.

提交回复
热议问题