简体   繁体   English

在Java中找到最小的浮点数

[英]finding the smallest floating point numbers in java

I really don't understand then,] as I not too good with maths. 那时我真的不明白,因为我对数学不太好。 I've searched around but I can't really find anything to help me. 我到处搜寻,但找不到真正能帮助我的东西。

what I need to know is which one of these floating point numbers is the smallest 我需要知道的是这些浮点数中哪一个最小

a. 一种。 28.268E-5f 28.268E-5f
b. b。 0.0000002763E4f 0.0000002763E4f
c. C。 282479.9E-9f 282479.9E-9f
d. d。 0.2764E-2f 0.2764E-2f

I'm not asking for the answer, if you don't want to give it to me, but more of a way for me to figure it out myself. 如果您不想把答案给我,我不是要答案,而是我自己想出办法的一种方式。 In simple terms. 简单来说。

This is basic maths, not specific to Java. 这是基本数学,不是特定于Java的。 The "E(some number)" bit is short for "10 to the power of (some number)". “ E(某数字)”位是“ 10等于(某数字)的幂”的缩写。

So 1E-5 is 1 x 10^-5 which is 0.00001 (1 divided by 10 5 times). 因此1E-5是1 x 10 ^ -5,即0.00001(1除以10 5倍)。

2E-5 would be 0.00002 and so on. 2E-5将为0.00002,依此类推。 Hopefully that gives you enough to figure out how to expand the numbers you have and see which is smallest. 希望这能给您足够的思路,弄清楚如何扩展现有数字,并查看最小的数字。

The answer is c) 282479.9E-9f 答案是c)282479.9E-9f

For your clarity E stands for exponent that is 10 power the digit following it. 为了您的清楚起见,E代表指数为10的幂。 so 1.0E-2 = 0.01 所以1.0E-2 = 0.01

28.268E-5f     = 0.00028268 
0.0000002763E4 = 0.002763 
282479.9E-9    = 0.0002824799
0.2764E-2      = 0.0027464

probably the safest bet is to create a float[] containing your values, and use an array sorting algorithm to order them smallest to largest, from there-on-in, you can find the smallest, largest, medium values. 可能最安全的选择是创建一个包含您的值的float [],然后使用数组排序算法将它们从最小到最大排序,然后从中找到最小,最大,中等的值。 Check this out. 看一下这个。 http://www.java-examples.com/java-sort-float-array-example http://www.java-examples.com/java-sort-float-array-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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