The Math.sin() method returns the trigonometric sine of an angle in radians.
Radian Angular Coordinates: Operates in radians; use Math.toRadians() for degree angles. Ratio spans -1.0 through 1.0. For cosine, see Math.cos(). For inverse sine, see Math.asin(). For hyperbolic sine, see Math.sinh().
Defined in java.lang.Math:
// Formal signature of Math.sin() in java.lang.Math
public static double sin(double a)
| Signature Element | Type | Description & Operational Rule |
|---|---|---|
a |
double |
The angle measured in radians (not degrees). |
| Return Value | double |
The trigonometric sine ratio, bounded within [-1.0, 1.0]. |
| Symmetry | Odd Function | Antisymmetric across origin: Math.sin(-a) == -Math.sin(a). |
Evaluating sine across fundamental radian angles and verifying odd function symmetry:
System.out.println(Math.sin(0.0)); // 0.0
System.out.println(Math.sin(Math.PI / 6)); // 0.49999999999999994 (~0.5)
System.out.println(Math.sin(Math.PI / 2)); // 1.0
System.out.println(Math.sin(-Math.PI / 2)); // -1.0 (odd function)Terminal Output:
0.0
0.49999999999999994
1.0
-1.0
Passing degree values directly treats them as radians. Always convert degrees first with Math.toRadians():
System.out.println(Math.sin(Math.toRadians(0))); // 0.0
System.out.println(Math.sin(Math.toRadians(30))); // 0.49999999999999994
System.out.println(Math.sin(Math.toRadians(90))); // 1.0
System.out.println(Math.sin(Math.toRadians(270))); // -1.0Terminal Output:
0.0
0.49999999999999994
1.0
-1.0
In mathematics, sin(180°) = 0. In Java, Math.sin(Math.PI) returns 1.2246467991473532E-16 because Math.PI is a finite 64-bit approximation. Always use an epsilon threshold or Math.round():
// THE 180-DEGREE TRAP: Math.sin(Math.PI) does NOT return exactly 0.0
double sin180 = Math.sin(Math.PI);
System.out.println("sin(PI) raw value: " + sin180); // 1.2246467991473532E-16
System.out.println("Equals 0.0? " + (sin180 == 0.0)); // false!
System.out.println("Tolerant zero check: " + (Math.abs(sin180) < 1e-12)); // trueTerminal Output:
sin(PI) raw value: 1.2246467991473532E-16
Equals 0.0? false
Tolerant zero check: true
Signed zero is preserved, while infinite arguments return Double.NaN:
System.out.println(Math.sin(-0.0)); // -0.0
System.out.println(Math.sin(Double.NaN)); // NaN
System.out.println(Math.sin(Double.POSITIVE_INFINITY)); // NaNTerminal Output:
-0.0
NaN
NaN
Comparing forward trigonometric methods in Java:
| Method | Ratio Formula | Return Range | Primary Use Case |
|---|---|---|---|
Math.sin(rad) |
Opposite / Hypotenuse | [-1.0, 1.0] |
Y-axis displacement, wave height, vertical elevation. |
Math.cos(rad) |
Adjacent / Hypotenuse | [-1.0, 1.0] |
X-axis displacement, orbital mechanics, horizontal vectors. |
Math.tan(rad) |
Opposite / Adjacent | (-infinity, +infinity) |
Slope calculations, camera field-of-view, gradients. |
Calculating vertical positions along a circular trajectory (paired with Math.cos() for X):
public class OrbitYCalculator {
public static double getOrbitY(double cy, double r, double deg) {
return cy + r * Math.sin(Math.toRadians(deg));
}
public static void main(String[] args) {
System.out.println("Y at 0 deg: " + getOrbitY(100, 50, 0)); // 100.0
System.out.println("Y at 90 deg: " + getOrbitY(100, 50, 90)); // 150.0
System.out.println("Y at 270 deg: " + getOrbitY(100, 50, 270)); // 50.0
}
}Terminal Output:
Y at 0 deg: 100.0
Y at 90 deg: 150.0
Y at 270 deg: 50.0
Sampling a pure sinusoidal wave y(t) = A * sin(2 * pi * f * t) over time:
public class SineWaveGenerator {
public static double wave(double a, double f, double t) {
return a * Math.sin(2.0 * Math.PI * f * t);
}
public static void main(String[] args) {
System.out.println(wave(10.0, 1.0, 0.25)); // 10.0 (peak)
System.out.println(wave(10.0, 1.0, 0.75)); // -10.0 (trough)
}
}Terminal Output:
10.0
-10.0
Calling Math.sin(30) treats 30 as 30 radians, returning -0.988 instead of 0.5. Always wrap degree values in Math.toRadians(30).
Testing Math.sin(Math.toRadians(180)) == 0.0 evaluates to false due to IEEE 754 precision limits (1.22e-16). Always use Math.abs(val) < 1e-12.
You can compile and run this complete verification class locally in any Java IDE or environment:
public class MathSinFullDemo {
public static void main(String[] args) {
// 1. Verify exact 90-degree sine is 1.0
if (Math.sin(Math.PI / 2.0) == 1.0) {
System.out.println("Check 1 Passed: sin(PI/2) is 1.0.");
}
// 2. Verify odd symmetry: sin(-x) == -sin(x)
if (Math.sin(-1.22) == -Math.sin(1.22)) {
System.out.println("Check 2 Passed: Odd function symmetry verified.");
}
// 3. Verify Pythagorean identity: sin^2(x) + cos^2(x) == 1.0
double s = Math.sin(0.85), c = Math.cos(0.85);
if (Math.abs((s * s + c * c) - 1.0) < 1e-12) {
System.out.println("Check 3 Passed: sin^2 + cos^2 == 1.0 verified.");
}
System.out.println("All Math.sin() verification checks passed successfully!");
}
}Terminal Output:
Check 1 Passed: sin(PI/2) is 1.0.
Check 2 Passed: Odd function symmetry verified.
Check 3 Passed: sin^2 + cos^2 == 1.0 verified.
All Math.sin() verification checks passed successfully!
Because Math.PI is a finite 64-bit IEEE 754 approximation of π, its sine evaluates to the residual offset 1.2246467991473532E-16.
Because Math.PI / 6 cannot be represented with infinite binary precision, the result is 1 ULP below 0.5.
Use Math.asin(ratio), which returns the angle in radians within [-pi/2, pi/2].
Math.sin() is the circular sine bounded to [-1.0, 1.0], while Math.sinh() is the unbounded hyperbolic sine (e^x - e^-x) / 2.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.