Skip to content

Commit 8295da8

Browse files
New Examples
1 parent 51656a4 commit 8295da8

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

0 commit comments

Comments
 (0)