我正在尝试制作一个角度程序来计算输入角度的 sin、cos 和 tan。这是我遇到问题的代码部分:
c.println ("You have entered an angle of " + angle + " degrees.");
radians = Math.toRadians (angle); //convert angle (which is in degrees) to radians(radians = (pi / 180)*degrees)
c.println ("The angle in radians is " + radians); //diplay angle in radians
//caluclating sine, cosine & tangent
double sinx = Math.sin (Math.toRadians (angle));
c.println ("The sine of the angle is " + sinx+ " radians."); //convert sin of angle (in deg) to radians
double cosx = Math.cos (Math.toRadians (angle));
c.println ("The cosine of the angle is " + cosx+ " radians.");//convert cos of angle (in deg) to radians
double tanx = Math.tan (Math.toRadians (angle));
c.println ("The tangent of the angle is " + tanx+ " radians.");//convert tan of angle (in deg) to radians
如果我输入一个 90 度的角度,余弦输出是 6.12^-17.... 当它应该只是 = 0。所以某处有计算错误?