关于math:Mathrandom的玩法

知识点1.Math.random() 随机数0.××××××× 2.toString() 将数字变成字符串, 不然substring辨认不了 3.substring(2, 4) 从第二个开始,到第四个完结(不算4) (0 1 2 3 4) 源码如下随机数变成字符串,而后再切割。最初包裹一个(),括号加一个+号就能悄悄的强制类型转换成数字。小于等于1就能中奖了 <div class="item"></div><script> var a = +(Math.random().toString().substring(2, 4)) var txt = document.querySelector(".item") if (a <= 1) { txt.innerHTML = "中奖了" txt.className = "item good" } else { txt.innerHTML = "未中奖" } console.log(typeof a, a)</script>.item { padding: 80px; background: rgb(0, 0, 0, 0.69) no-repeat; width: 400px; margin: 0 auto; color: #ffffff; text-align: end; border-radius: 10px; font-size: 35px; font-family: 微软雅黑; font-weight: bolder; background-image: url(https://img.zcool.cn/community/01e5ed5bbb4d7ba801213deaff734c.gif);}.good { background: #f23b3e no-repeat; background-image: url(https://img.zcool.cn/community/01adf25bbb4d72a8012099c8c4ba5b.gif);} ...

October 14, 2022 · 1 min · jiezi

关于math:换底公式之推导

\begin{array}{c}换底公式之推导:\\证实:\quad \log_{a}{b}=\frac{\log_{c}{b}}{\log_{c}{a}} \\设:\\\log_{a}{b} =r\\\log_{c}{b} =m\\\log_{c}{a} =n\\即:\\a^r=b\\c^m=b\\c^n=a\\\because a^r=(c^n)^r=b\\\because c^m=b\\\therefore c^m=c^{nr}\\\therefore m=nr\\\because r=\frac{m}{n} \\\therefore \log_{a}{b}=\frac{\log_{c}{b}}{\log_{c}{a}}\\\end{array}

March 25, 2022 · 1 min · jiezi

关于math:十字相乘法推导

\begin{array}{c}十字相乘法之推导:\\设方程\quad (ax+b)(cx+d)=0;\quad (等式左边必须为0)\\则失去:\quad acx^2+(ad+dc)x+bd\\与个别式\quad Ax^2+Bx+C=0\quad 比照:\\A=ac\\B=ad+dc\\C=bd\\即:\\a\quad \quad b\\c\quad \quad d\\重点为4个系数与B的关系:\quad ad+dc=B\\\end{array}

March 25, 2022 · 1 min · jiezi

关于math:二次函数一般式转为顶点式

latex source: \begin{array}{c}一元二次函数式:f(x) = ax^2+bx+c (a≠0)\\令其转化为顶点式形如:f(x) = a(x+h)^2+k (a≠0)的模式\\过程如下:ax^2+bx+c\\a(x^2+\frac{b}{a} x)+c\\a[x^2+\frac{b}{a} x+(\frac{b}{2a})^2]-(\frac{ab^2}{4a^2})+c\\a(x^2+\frac{b}{a}x+\frac{b^2}{4a^2})-\frac{b^2}{4a}+c\\ a(x+\frac{b}{2a} )^2+c-\frac{b^2}{4a}\\ a(x+\frac{b}{2a} )^2+\frac{4ac-b^2}{4a} \\ 因为f(x) = a(x+h)^2+k 的顶点坐标为:(-h,k)\\所以f(x) = ax^2+bx+c 的顶点坐标为:(-\frac{b}{2a},\frac{4ac-b^2}{4a})\\f(x)的图像对于x=-\frac{b}{2a} 对称\end{array}

March 25, 2022 · 1 min · jiezi

关于math:Math类的三个方法比较-floor-ceil-round

public class Test { public static void main(String[] args) { double d1 = 3.4, d2 = 3.6; //负数 double d3 = -3.4, d4 = -3.6; //正数 float f1 = 4.4F, f2 = 4.6F; //负数 float f3 = -4.4F, f4 = -4.6F; //正数 //floor()办法只能接管double类型,返回double类型 //向下取整,返回小于参数的最大整数 System.out.println(Math.floor(d1));//3.0 System.out.println(Math.floor(d2));//3.0 System.out.println(Math.floor(d3));//-4.0 System.out.println(Math.floor(d4));//-4.0 //ceil()办法只能接管double类型,返回double类型 //向上取整,返回大于参数的最小整数 System.out.println(Math.ceil(d1));//4.0 System.out.println(Math.ceil(d2));//4.0 System.out.println(Math.ceil(d3));//-3.0 System.out.println(Math.ceil(d4));//-3.0 //round()办法能够接管double类型,返回long类型 //示意“四舍五入”,算法为Math.floor(x+0.5),行将参数加上0.5后再向下取整 System.out.println(Math.round(d1));//3 System.out.println(Math.round(d2));//4 System.out.println(Math.round(d3));//-3 System.out.println(Math.round(d4));//-4 //round()办法能够接管float类型,返回int类型 System.out.println(Math.round(f1));//4 System.out.println(Math.round(f2));//5 System.out.println(Math.round(f3));//-4 System.out.println(Math.round(f4));//-5 }}

January 5, 2021 · 1 min · jiezi

关于math:Go四舍五入在go语言中为何如此困难

四舍五入是一个十分常见的性能,在风行语言规范库中往往存在 Round 的性能,它起码反对罕用的 Round half up 算法。 而在 Go 语言中这仿佛成为了难题,在 stackoverflow 上搜寻 [go] Round 会存在大量相干发问,Go 1.10 开始才呈现 math.Round 的身影,本认为 Round 的疑难就此结束,然而一看函数正文 Round returns the nearest integer, rounding half away from zero ,这是并不罕用的 Round half away from zero 实现呀,说白了就是咱们了解的 Round 阉割版,精度为 0 的 Round half up 实现,Round half away from zero 的存在是为了提供一种高效的通过二进制办法得后果,能够作为 Round 精度为 0 时的高效实现分支。 带着对 Round 的‘敬畏’,我在 stackoverflow 翻阅大量对于 Round 问题,开启寻求最佳的答案,本文整顿我认为有用的实现,简略剖析它们的优缺点,对于不想逐渐理解,想间接看后果的小伙伴,能够间接看文末的最佳实现,或者跳转 exmath.Round 间接看源码和应用吧! <!--more--> Round 第一弹在 stackoverflow 问题中的最佳答案首先取得我的关注,它在 mathx.Round 被开源,以下是代码实现: ...

January 2, 2021 · 3 min · jiezi