473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Is there any constant defined for infinity in java

I am writing a class which contain a variable INFINITY. Is there any constant defined for this in java so that i can assign that value?

In .NET, there is System.Threading.Timeout.Infinite for infinity. I am looking for the same in java also.
Mar 13 '07 #1
13 47611
hirak1984
316 100+
No idea , eager to know if there is any!!!
Mar 13 '07 #2
Ganon11
3,652 Expert 2GB
What do you need infinity for?
Mar 13 '07 #3
r035198x
13,262 8TB
For the numeric wrapper types.

e.g Double.POSITVE_INFINITY
Mar 13 '07 #4
What do you need infinity for?
I have a function WaitOnMultipleEvents( long lMilliseconds ) in the class. So the parameter value is set to m_lMilliseconds member variable which means how much time it has to wait.

when lMilliseconds is less than 0, i want to set the m_lMilliseconds to infinity. So what value should i assign for it.
Mar 14 '07 #5
r035198x
13,262 8TB
I have a function WaitOnMultipleEvents( long lMilliseconds ) in the class. So the parameter value is set to m_lMilliseconds member variable which means how much time it has to wait.

when lMilliseconds is less than 0, i want to set the m_lMilliseconds to infinity. So what value should i assign for it.
lMilliseconds is a long. The largest value it can take is the largest value for the long data type which is 2^(63) - 1
Mar 14 '07 #6
lMilliseconds is a long. The largest value it can take is the largest value for the long data type which is 2^(63) - 1

i mean, i want to assign m_lmilliSeconds a value which means it is infinity. Like, i can assign -1 to represent it is infinity. But instead of that juz wanted to know if any constant value is already defined in java for this like what is there in .NET ( System.Threading.Timeout.Infinity ).
Mar 14 '07 #7
r035198x
13,262 8TB
i mean, i want to assign m_lmilliSeconds a value which means it is infinity. Like, i can assign -1 to represent it is infinity. But instead of that juz wanted to know if any constant value is already defined in java for this like what is there in .NET ( System.Threading.Timeout.Infinity ).
You can only assign a value that is withing the range of the type of the variable. You cannot store a number greater than 2^(63) -1 in a variable of type long. Remember that infinity itself is not a number. You can only find a very large number to represent it. That is what .NET or any other languages do. In Java there is an infinities for each of the numeric types. If you need a number larger than the numeric types you can use either BigInteger or BigDecimal.
Mar 14 '07 #8
RedSon
5,000 Expert 4TB
I have a function WaitOnMultipleEvents( long lMilliseconds ) in the class. So the parameter value is set to m_lMilliseconds member variable which means how much time it has to wait.

when lMilliseconds is less than 0, i want to set the m_lMilliseconds to infinity. So what value should i assign for it.

Did you write the method WaitOnMultipleEvents? That sounds like a standard named events method in win32 programming. For that method you usually need two things, a collection of the events to wait on and the maximum amount of time you want it to wait for. If you make the maximum amount of time to wait zero then usually the method interprets that as wait forever, since it doesnt make much sense to wait for 0 milliseconds or it would never wait, which is why it would be pointless to call the method anyway.

I say "usually" because this is the java forum and I have never heard of a java class the emulates the named event processing found in win32. If you have written it yourself then just change it to mean that zero is equal to infinity and there you have it.
Mar 14 '07 #9
reply to post #8: Not fully true...

Check this code:
f
Expand|Select|Wrap|Line Numbers
  1. or(double j=1; ;j++) {
  2.     double temp = Double.MAX_VALUE - j;
  3.     if(temp != Double.MAX_VALUE) {
  4.         break;
  5.     }
  6. }
When do you think you will leave the loop?

Double is trying to implement the mathematical infinite representation.

My 2 cents.
May 21 '10 #10
I also want to know how to use infinity. Reason why I want to use it is, is because there is a formula I made on paper that won't work unless the difference between two variables is an integer. So sort of how I want to use it

int soandso=(value for infinity);
float x=in.nextFloat();
float n=in.nextFloat
int abx=0;
int abn=0;
if (x<0){
abx=(0-x);
}
if (x>=0){
abx=x;
}
if (n<0){
abn=(0-n);
}
if (n>=0){
abn=n;
}
int dif=abx-abn;
while (dif!=soandso){
n=in.nextFloat();
if (x<0){
abx=(0-x);
}
if (x>=0){
abx=x;
}
if (n<0){
abn=(0-n);
}
if (n>=0){
abn=n;
}
dif=abx-abn;
}

this would make it so the user would have to continue reentering a value for n until the difference between abx and abn is an interger reason why it needs to absolute value is because there is such thing as something like .64-(-.36)=1
Nov 14 '11 #11
no. their is no constant/keyword like Infinity in java. Still you get a result Infinity when you work with floating point literals

"Infinity" is produced if a floating point operation creates such a large floating-point number that it cannot be represented normally. "Infinity" is a special value that represent the concept of positive infinity.

1.0 / 0.0 -> Infinity
Nov 28 '11 #12
Instead of infinity try using the max value of the datatype.
Dec 19 '11 #13
edk2
1
According to Javadocs, as far as wait() is concerned, 0 == infinity...

http://docs.oracle.com/javase/6/docs...wait%28long%29

"The specified amount of real time has elapsed, more or less. If timeout is zero, however, then real time is not taken into consideration and the thread simply waits until notified."
Sep 28 '12 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Amit | last post by:
Hi, I am trying to use INFINITY in a c++ code that I have written. I am using gcc 3.3 on os X 10.3.9 The compiler gives a warning warning: floating constant exceeds range of "float" My code...
33
by: patrick_woflian | last post by:
hey guys, im just writing a basic calculation at the moment, before building on it for an A-Level piece of work. i can add/divide etc... two numbers together yet i am having a major problem with...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
9
by: IchBin | last post by:
I am trying to get Java to work from within PHP. I have been looking at: http://us2.php.net/java The error and line of PHP code: $system = new Java('java.lang.System'); Fatal error: Class...
5
by: Peter Hansen | last post by:
I'm investigating a puzzling problem involving an attempt to generate a constant containing an (IEEE 754) "infinity" value. (I understand that special float values are a "platform-dependent...
9
by: misdst23 | last post by:
Hi, I know I can call a static java method within javascript by using the <% ... %tags. But how can pass a javascript variable ? function thefunction() { var = javascriptvariable ;
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: Bob Bryan | last post by:
Hi, I am writing a windows app in C# and referencing a lib built in J# and which I don't have the code for that requires a method to be overridden that contains a parameter defined as: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.