English 中文(简体)
C类合法转换
原标题:Implicit type conversion in C
最佳回答

平等经营人无:普通算术转换”,从以下开始:

  • First, if the corresponding real type of either operand is long double, the other operand is converted, without change of type domain, to a type whose corresponding real type is long double.
  • Otherwise, if the corresponding real type of either operand is double, the other operand is converted, without change of type domain, to a type whose corresponding real type is double.
  • Otherwise, if the corresponding real type of either operand is float, the other operand is converted, without change of type domain, to a type whose corresponding real type is float.

最后一个案例在此适用:i_ Value 改为float

比较结果如下:d 尽管如此/em>,但可以得出奇数:

The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby.

正在做的是:转换的<代码>i_ Value的类型仍在float,但在这个表述中,贵编者正在利用这一纬度,并比float更为精确。 这是汇编387个可比较的浮动点时的典型编纂者行为,因为汇编者在浮动点上留下临时价值,该浮点以80个轨道扩展精确格式储存浮动点数。

如果您的汇编者为gcc,那么你可以通过提供<代码>-ffloat-store<>/code>的指挥线选择来消除这一额外准确性。

问题回答

这里有一些很好的答案。 你们必须非常谨慎地改变各种分类和各个浮动点的表述。

总的来说,我没有为平等测试浮动点号码,特别是如果其中一点来自一种隐蔽的或明确的分类。 我处理的是完全由几何计算的申请。 我们尽可能地与正常的分类账合作(迫使我们在投入数据中接受最大精确度)。 如果你必须使用浮动点,如果需要比较,我们将对差异适用绝对值。

我认为,拥有一个32个电算机的电算点的最大电算值是1048576,低于上述数字。 因此,毫无疑问,浮动点值将不持有16777217美元。

The part I m not sure about is how the compiler makes the comparison between two different types of numbers (i.e. a float and an int). I can think of three different ways this might be done:

(1) 将这两种数值转换为“float”(这应当使数值相同,因此可能不是汇编者所做的那样)

2) 将两种数值转换为“int”(这种数值可能或可能不会显示相同......转换成经常为truncate,因此,如果浮动点值为16777216.999,则改成“int”即行)。

3) Convert both values to "double". My guess would be that this is what the compiler would do. If this is what the compiler does, the two values would definitely be different. A double can hold 16777217 exactly, and it could also exactly represent the float point value that 16777217.0 converts to (which is not exactly 16777217.0).





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...