gpt4 book ai didi

mysql - MySQL 中无符号 FLOAT 值的范围

转载 作者:行者123 更新时间:2023-11-29 05:08:25 25 4
gpt4 key购买 nike

根据MySQL Numeric types documentation ,除此之外,Float 类型具有以下属性:

FLOAT[(M,D)] [UNSIGNED] [ZEROFILL]

A small (single-precision) floating-point number. Permissible values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system.

M is the total number of digits and D is the number of digits following the decimal point. If M and D are omitted, values are stored to the limits permitted by the hardware. A single-precision floating-point number is accurate to approximately 7 decimal places.

UNSIGNED, if specified, disallows negative values.

我想确定 unsigned float 的行为是否类似于 unsigned int 的行为,其中小数和尾数的完整位深度用于表示正值,或者如果 unsigned float 仅防止负值。

最佳答案

I want to determine if the behavior of unsigned float is similar to the behavior of unsigned int where the the full bit depth of the decimal and mantissa is used to represent positive values, or

没有。 MySQL 选择为其 FLOAT 使用 IEEE-754 单精度 float 。 IEEE Float 是“sign-magnitude”,所以符号位占据它自己的特定位置。另一方面,INT 是 2 的补码编码。因此,符号位既可以解释为符号,也可以解释为值的扩展。 (注意:几乎所有当前的计算机硬件 都按照本段中描述的方式工作;但可能有些不是。一个古老的例子:CDC 6600 使用 1 的补码。)

if unsigned floats only prevent negative values.

是的。

必须要说的是:如果您使用的是本质上不精确的 FLOAT 数据类型,您应该仔细考虑为什么您的问题空间禁止所有负数。这些数字是否忠实地代表了问题空间? FLOAT 的不精确性是否可以接受您所代表的内容?

float 可以无计算的想法是虚幻的。仅从整数生成它们就涉及计算。是的,它是直接在计算机芯片上完成的,但它仍然是计算。

并且,丢包的例子是

  1. 精确地用两个整数表示:丢失的数据包数/数据包数(如果你愿意,你可以称之为有理数),或者
  2. 大约由一个 FLOAT 分数表示,该分数是将这些整数中的一个除以另一个得到的。

恕我直言,你想多了。

FLOAT 总是占用 4 个字节,无论附加的选项如何。另一方面,DECIMAL(m,n) 占用大约 (m/2) 个字节。

FLOAT(m,n),可能没用。 n 表示将 in decimal 舍入到 n 位,然后存储为二进制数(IEEE Float),从而导致另一个舍入。 p>

关于mysql - MySQL 中无符号 FLOAT 值的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44011953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com