Is the parameter in the method call the correct type?

A good answer might be:

Yes—so no conversion is required.

Examples with Floating-point Types

Here is a program where the supplied parameter type does not match the required type:

class CosEg2
{

  public static void main ( String arg[] )
  {
    int z = 0;

    System.out.println( "cos is:" + Math.cos( z ) );
  }
}

In this case, the 32 bit value in x can be converted to the required 64 bit value without loss of information, so the compiler does it automatically. Here is another case:

class CosEg3
{

  public static void main ( String arg[] )
  {
    long w = 0;

    System.out.println( "cos is:" + Math.cos( w ) );
  }
}

Data of type long can be converted to type double, but some precision may be lost. In this case, also, the compiler does the conversion automatically. (In this particular case, no precision is lost because 0 can be represented accurately in both types. But in general, there may be loss of precision in converting from long to double.)

QUESTION 10:

(Thought question:) Do you think that the following will work:


class cosEg4
{

  public static void main ( String arg[] )
  {
    long w = 0;

    System.out.println( "cos is:" + Math.cos( (double)w ) );
  }
}