MCPcopy Create free account
hub / github.com/Aghajari/MathParser / fixDegrees

Method fixDegrees

MathParser/src/com/aghajari/math/MathParser.java:212–228  ·  view source on GitHub ↗

Makes degrees readable for Math trigonometry functions x° => toRadians(x)

(String src)

Source from the content-addressed store, hash-verified

210 * x° => toRadians(x)
211 */
212 private String fixDegrees(String src) {
213 char deg = '°';
214 // 24deg | 24degrees => 24°
215 // 24rad | 24 radian | 24radians => 24
216 if (getVariable("degrees") == null)
217 src = src.replaceAll("(?<=\\d)degrees(?=[^\\w]|$)", String.valueOf(deg));
218 if (getVariable("deg") == null)
219 src = src.replaceAll("(?<=\\d)deg(?=[^\\w]|$)", String.valueOf(deg));
220 if (getVariable("radians") == null)
221 src = src.replaceAll("(?<=\\d)radians(?=[^\\w]|$)", "");
222 if (getVariable("radian") == null)
223 src = src.replaceAll("(?<=\\d)radian(?=[^\\w]|$)", "");
224 if (getVariable("rad") == null)
225 src = src.replaceAll("(?<=\\d)rad(?=[^\\w]|$)", "");
226
227 return fix(src, "toRadians", deg);
228 }
229
230 /**
231 * Makes factorial readable

Callers 1

firstSimplifyMethod · 0.95

Calls 2

getVariableMethod · 0.95
fixMethod · 0.95

Tested by

no test coverage detected