File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
src/main/java/com/howtodoinjava/core/basic Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .howtodoinjava .core .basic ;
2
+
3
+ public class MathAbsoluteExamples {
4
+
5
+ public static void main (String [] args ) {
6
+
7
+ double doubleValue = -10.56 ;
8
+ float floatValue = -7.8f ;
9
+ int intValue = -15 ;
10
+ long longValue = -123456789L ;
11
+
12
+ System .out .println (STR ."Absolute value of double: \{Math .abs (doubleValue )}" );
13
+ System .out .println (STR ."Absolute value of float: \{Math .abs (floatValue )}" );
14
+ System .out .println (STR ."Absolute value of int: \{Math .abs (intValue )}" );
15
+ System .out .println (STR ."Absolute value of long: \{Math .abs (longValue )}" );
16
+
17
+ //Overflow / Underflow Issue
18
+
19
+ int intMinValue = Integer .MIN_VALUE ;
20
+ long longMinValue = Long .MIN_VALUE ;
21
+
22
+ System .out .println (STR ."Absolute value of int: \{Math .abs (intMinValue )}" );
23
+ System .out .println (STR ."Absolute value of long: \{Math .abs (longMinValue )}" );
24
+
25
+ System .out .println (STR ."Absolute value of int: \{Math .absExact (intMinValue )}" );
26
+ System .out .println (STR ."Absolute value of long: \{Math .absExact (longMinValue )}" );
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ package com .howtodoinjava .core .basic ;
2
+
3
+ public class StricfpExample {
4
+
5
+ public static void main (String [] args ) {
6
+ runMethod ();
7
+ }
8
+
9
+ strictfp public static void runMethod () {
10
+ double x = 5.899999 ;
11
+ double y = 13.888345 ;
12
+ double z = 14.463534545 ;
13
+
14
+ double m1 = (x * y ) * z ; // 1185.1596894396725
15
+ double m2 = (x * (y * z )); // 1185.1596894396728
16
+
17
+ System .out .println (m1 );
18
+ System .out .println (m2 );
19
+
20
+ System .out .println (m1 == m2 ); //false
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments