Skip to main content
deleted 19 characters in body
Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

I'll only deal with Problem 1 here since the rest should be clear to your from experimentation, once this bug is fixed.

It's Java: I think you need to convert long <-> double correctly. That would be why you're getting zero. Set up a very simple example where you just cast a doubledouble to a longlong and do vice versa with two separate variables, and see what happens. You should quickly enough findsee the problem. I believe the value is being truncated or somesuch.. You can alternatively try using long for everything. not to mention that you

You are also involving an integer literal (1000) in that expression as well, further complicating thingstype concerns. I suggest explicitly casting each term to double.

Once you have solved that, you should be able to answer the rest yourself, from the running codeand making 1000.0 i.e. a double.

I think you need to convert long <-> double correctly. That would be why you're getting zero. Set up a very simple example where you just cast a double to a long and do vice versa with two separate variables, and see what happens. You should quickly enough find the problem. I believe the value is being truncated or somesuch... not to mention that you are also involving an integer literal (1000) in that expression as well, further complicating things. I suggest explicitly casting each term to double.

Once you have solved that, you should be able to answer the rest yourself, from the running code.

I'll only deal with Problem 1 here since the rest should be clear to your from experimentation, once this bug is fixed.

It's Java: I think you need to convert long <-> double correctly. That would be why you're getting zero. Set up a very simple example where you just cast a double to a long and do vice versa with two separate variables, and see what happens. You should quickly see the problem. I believe the value is being truncated or somesuch. You can alternatively try using long for everything.

You are also involving an integer literal (1000) in that expression, further complicating type concerns. I suggest explicitly casting each term to double, and making 1000.0 i.e. a double.

Source Link
Engineer
  • 30.4k
  • 4
  • 76
  • 124

I think you need to convert long <-> double correctly. That would be why you're getting zero. Set up a very simple example where you just cast a double to a long and do vice versa with two separate variables, and see what happens. You should quickly enough find the problem. I believe the value is being truncated or somesuch... not to mention that you are also involving an integer literal (1000) in that expression as well, further complicating things. I suggest explicitly casting each term to double.

Once you have solved that, you should be able to answer the rest yourself, from the running code.