Mercurial Hosting > luan
comparison core/src/luan/modules/MathLuan.java @ 244:0a8e6fdb62f0
fix Math.random()
git-svn-id: https://luan-java.googlecode.com/svn/trunk@245 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 09 Oct 2014 22:44:07 +0000 |
parents | ec016471c6eb |
children | 58752e3e4c5c |
comparison
equal
deleted
inserted
replaced
243:c912f6de2053 | 244:0a8e6fdb62f0 |
---|---|
30 add( module, "max", Double.TYPE, new double[0].getClass() ); | 30 add( module, "max", Double.TYPE, new double[0].getClass() ); |
31 add( module, "modf", Double.TYPE ); | 31 add( module, "modf", Double.TYPE ); |
32 module.put("pi",Math.PI); | 32 module.put("pi",Math.PI); |
33 add( module, "pow", Double.TYPE, Double.TYPE ); | 33 add( module, "pow", Double.TYPE, Double.TYPE ); |
34 add( module, "rad", Double.TYPE ); | 34 add( module, "rad", Double.TYPE ); |
35 add( module, "random" ); | 35 add( module, "random", Integer.class, Integer.class ); |
36 add( module, "sin", Double.TYPE ); | 36 add( module, "sin", Double.TYPE ); |
37 add( module, "sinh", Double.TYPE ); | 37 add( module, "sinh", Double.TYPE ); |
38 add( module, "sqrt", Double.TYPE ); | 38 add( module, "sqrt", Double.TYPE ); |
39 add( module, "tan", Double.TYPE ); | 39 add( module, "tan", Double.TYPE ); |
40 add( module, "tanh", Double.TYPE ); | 40 add( module, "tanh", Double.TYPE ); |
124 | 124 |
125 public static double rad(double x) { | 125 public static double rad(double x) { |
126 return Math.toRadians(x); | 126 return Math.toRadians(x); |
127 } | 127 } |
128 | 128 |
129 public static double random() { | 129 public static double random(Integer m,Integer n) { |
130 return Math.random(); | 130 if( m==null ) |
131 return Math.random(); | |
132 if( n==null ) | |
133 return Math.floor(m*Math.random()) + 1; | |
134 return Math.floor((n-m)*Math.random()) + m; | |
131 } | 135 } |
132 | 136 |
133 public static double sin(double x) { | 137 public static double sin(double x) { |
134 return Math.sin(x); | 138 return Math.sin(x); |
135 } | 139 } |