Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error : Square root a Float

 
Conrad McLaughlin
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
222: incompatible types
found : double
required: java.lang.Float
VL = Math.sqrt(VL); //Square root


Can't you square root a number if it is a float?
(VL is declared as a float.)
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Conrad McLaughlin:
222: incompatible types
found : double
required: java.lang.Float
VL = Math.sqrt(VL); //Square root


Can't you square root a number if it is a float?
(VL is declared as a float.)


Sure you can. What the compiler is complaining about is assigning a double to a float, so cast it:

VL = (float) Math.sqrt(VL);
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Conrad McLaughlin:
...VL is declared as a float...

I don't think so. It looks like VL is declared as a Float (object) -- not a float (primitive). The cast will work, but there's a lot of boxing/unboxing going on here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic