Java double value not getting calculated properly
I have the simple following code
public class Test {
public static void main(String args[])
{
double d=11111111111111111.0 * 10.0;
System.out.println((long)(d));
}
}
Here I am getting output as 1111111111111111120 rather than 111111111111111110. please tell me why this is happening and how to overcome this?
See also questions close to this topic

Trying to find the smallest number in an array
I am trying to find the smallest number in my array. The program is outputting the correct value for the largest number but it keeps outputting 0 as the smallest.
double largestlat = arlat[0]; //north double smallestlat = arlat[0]; //south for(int i = 1; i<arlat.length; i++) { if(arlat[i] > largestlat) { largestlat = arlat[i]; } } for(int i = 1; i<arlat.length; i++) { if(arlat[i] < smallestlat) { smallestlat = arlat[i]; } }`
The full code can be found here Link

matching strings in java using a loop
I'm having a hard time writing this class isValidMonthAbbr my for loop is always returning false how to how fix this loop tho match the appreciation to full month name
private static String[] abbrMonths = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" }; //Another static variable you can use, except these contain the months fully spelled out private static String[] fullNameMonths = { "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" };
public static boolean isValidMonthAbbr(String str) {
String month = str.trim(); int mLen = month.length(); String m1=""; for( int i = 0; i< abbrMonths.length ; i++) { m1 = fullNameMonths[i].substring(0,mLen); boolean compare = month.equalsIgnoreCase(m1); if (compare == false) { return false; } } return true;

2D for loop always jumping to else case
I'm building a game board where some pieces on the game are invalid those are signified by a 1 and valid positions on the board I decided to use 0. This method makes a 2d array board and assigns values to the spots on the board. I used a nested forloop to parse through the board:
public int[][] makeBoard() { int[][] board = new int[arrayLength][arrayLength]; for (int col = 0; col < arrayLength; col++) { for (int row = 0; row < arrayLength; row++) { //left top if (col <= armThickness  2 && row <= armThickness  2) { board[col][row] = 1; } else { board[col][row] = 0; } } } return board;
I pass this method the coordinates (0, 1) where 0 is the column and 1 is the row. If the armthickness is 3, and the arraylength is 7, the method should return a 1, since the col is less than 1, and the row is = to 1. However whatever combo of coordinates and arm thickness that I pass in jumps directly to the else case, 0. Is there a reason that all of my cases fall through?

Java  Double close to zero is infinity
I'm currently facing an unexpected issue in my java program. I have to do multiple arithmetic operations on numbers (which are double), and i saw an infinity value appear in my double array.
Reversing the problem shows that doing a square of a really small double variable gives an infinite result :
// Value of a = 4.8484439536882894E154 double b = a*a; // Math.pow(a,2) give the same result
I understand that an operation like the following :
double b = a/0.0;
would give me an infinite result, but here i would expect to see zero, i'm confused.
I see two ways to solve this problem :
 Change the type of my numbers (maybe for the type "BigDecimal" ?)
 Round my numbers to make them equal to zero when they are really small.
My main concern is that i have efficiency constraints (i do a lot of operations), and i would like to know the most efficient solution.

The delta parameter of Assert.AreEqual thinks I'm passing a string instead of a double
This is the function I'm trying to use:
I threw in some double just for an example, and this is my error:
Likewise, I've tried ints and floats instead, but it always thinks I'm trying to give it a string. What did I do wrong?
I'm using Visual Studio on a Windows 10 64bit, though I don't think that'll help.

C++: How does std::isinf() and std::isnan() judge if a double is invalid?
We know that floating number is of IEEE754 standard, so no matter what is being stored in the 32/64 bits of a floating number, we can see the value of this number. So how isinf/isnan implemented and what's the principle behind it?
Thanks a lot.