简体   繁体   中英

Java Arcsin not outputting correct value

arcsin is outputting the wrong answer while sin works as intended and I have no idea why this is happening

if (func.equals("sqrt")) x = Math.sqrt(x);
else if (func.equals("sin")) x = Math.sin(Math.toRadians(x));
else if (func.equals("arcsin")) x = Math.asin(Math.toRadians(x));
else throw new RuntimeException("Unknown function: " + func);

The input to arc sin isn't an angle, so don't convert x to radians first.

It's hard to know exactly what you intend, but perhaps you mean:

x = Math.toDegrees(Math.asin(x));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM