Presentation is loading. Please wait.

Presentation is loading. Please wait.

Floating Point ValuestMyn1 Floating Point Values Internally, floating point numbers have three pairs: a sign (positive or negative), a mantissa (has a.

Similar presentations


Presentation on theme: "Floating Point ValuestMyn1 Floating Point Values Internally, floating point numbers have three pairs: a sign (positive or negative), a mantissa (has a."— Presentation transcript:

1 Floating Point ValuestMyn1 Floating Point Values Internally, floating point numbers have three pairs: a sign (positive or negative), a mantissa (has a fixed number of digits) and an exponent. You can write a floating point literal in three basic forms: –as a decimal value including a decimal point, for example 110.0. –with an exponent, for example 11E1 (or 11e1). –using both a decimal point and an exponent, for example 1.1E2.

2 Floating Point ValuestMyn2 There are two floating point data types: –float, single precision floating point values –double, double precision floating point values The term precision refers to the number of significant digits in the mantissa. The data types are in order of increasing precision, with float providing the lowest number of digits in the mantissa. The precision only determines the number of digits in mantissa.

3 Floating Point ValuestMyn3 The range of numbers that can be represented by a particular type is determined primarly by the range of possible exponents. Of the two, double is the most commonly used: double mass=64.9;

4 Floating Point ValuestMyn4 package hypotenuse; public class Main { public static void main(String[] args) { double x=12.67; double y=7.74; double z=Math.sqrt(x*x+y*y); System.out.println("Hypotenuse is "+z+"."); } run: Hypotenuse is 14.847104094738475. BUILD SUCCESSFUL (total time: 0 seconds)

5 Floating Point ValuestMyn5 package maxdouble; public class Main { public static void main(String[] args) { double num1=1.12E13; double num2=-2.67e-7; System.out.println("Two samples: "+num1+" and "+num2); System.out.println("The max value of type double is "+ Double.MAX_VALUE); } run: Two samples: 1.12E13 and -2.67E-7 The max value of type double is 1.7976931348623157E308 BUILD SUCCESSFUL (total time: 2 seconds)


Download ppt "Floating Point ValuestMyn1 Floating Point Values Internally, floating point numbers have three pairs: a sign (positive or negative), a mantissa (has a."

Similar presentations


Ads by Google