ieee-754

how many whole numbers in IEEE 754

青春壹個敷衍的年華 提交于 2019-11-27 19:32:09
问题 I am trying to figure out how many different whole numbers exist in the ieee 754. The number I got was 1778384895 but I couldn't find any resource to check myself. Thanks a lot in advance. 回答1: I will assume single precision floats. We got the zero, which although can be represented as negative zero, is still just zero as an integer so I count it as one. Numbers with exponent less than 127 are not integers. Exponent Free bits # Numbers 127 0 1 128 1 2 129 2 4 ... 149 22 2^22 These sum up to 2

Ensuring C++ doubles are 64 bits

强颜欢笑 提交于 2019-11-27 18:50:44
In my C++ program, I need to pull a 64 bit float from an external byte sequence. Is there some way to ensure, at compile-time, that doubles are 64 bits? Is there some other type I should use to store the data instead? Edit: If you're reading this and actually looking for a way to ensure storage in the IEEE 754 format, have a look at Adam Rosenfield's answer below. An improvement on the other answers (which assume a char is 8-bits, the standard does not guarantee this..). Would be like this: char a[sizeof(double) * CHAR_BIT == 64]; or BOOST_STATIC_ASSERT(sizeof(double) * CHAR_BIT == 64); You

Usefulness of signaling NaN?

喜欢而已 提交于 2019-11-27 18:28:14
I've recently read up quite a bit on IEEE 754 and the x87 architecture. I was thinking of using NaN as a "missing value" in some numeric calculation code I'm working on, and I was hoping that using signaling NaN would allow me to catch a floating point exception in the cases where I don't want to proceed with "missing values." Conversely, I would use quiet NaN to allow the "missing value" to propagate through a computation. However, signaling NaNs don't work as I thought they would based on the (very limited) documentation that exists on them. Here is a summary of what I know (all of this

How do I convert from a decimal number to IEEE 754 single-precision floating-point format?

∥☆過路亽.° 提交于 2019-11-27 18:11:56
How would I go about manually changing a decimal (base 10) number into IEEE 754 single-precision floating-point format? I understand that there is three parts to it, a sign, an exponent, and a mantissa. I just don't completely understand what the last two parts actually represent. Find the largest power of 2 which is smaller than your number, e.g if you start with x = 10.0 then 2 3 = 8, so the exponent is 3. The exponent is biased by 127 so this means the exponent will be represented as 127 + 3 = 130. The mantissa is then 10.0/8 = 1.25. The 1 is implicit so we just need to represent 0.25,

Float precision bits

亡梦爱人 提交于 2019-11-27 16:24:48
In this wiki article it shows 23 bits for precision, 8 for exponent, and 1 for sign Where is the hidden 24th bit in float type that makes (23+1) for 7 significand digits? Floating point numbers are usually normalized. Consider, for example, scientific notation as most of us learned it in school. You always scale the exponent so there's exactly one digit before the decimal point. For example, instead of 123.456, you write 1.23456x10 2 . Floating point on a computer is normally handled (almost 1 ) the same way: numbers are normalized so there's exactly one digit before the binary point (binary

Turn float into string

我的未来我决定 提交于 2019-11-27 16:23:50
I have proceeded to state when I need to turn IEEE-754 single and double precision numbers into strings with base 10 . There is FXTRACT instruction available, but it provides only exponent and mantissa for base 2, as the number calculation formula is: value = (-1)^sign * 1.(mantissa) * 2^(exponent-bias) If I had some logarithmic instructions for specific bases, I would be able to change base of 2 exponent - bias part in expression, but currently I don't know what to do. I was also thinking of using standard rounded conversion into integer, but it seems to be unusable as it doesn't offer

flush-to-zero behavior in floating-point arithmetic

余生长醉 提交于 2019-11-27 14:49:51
问题 While, as far as I remember, IEEE 754 says nothing about a flush-to-zero mode to handle denormalized numbers faster, some architectures offer this mode (e.g. http://docs.sun.com/source/806-3568/ncg_lib.html ). In the particular case of this technical documentation, standard handling of denormalized numbers is the default, and flush-to-zero has to be activated explicitly. In the default mode, denormalized numbers are also handled in software, which is slower. I work on a static analyzer for

next higher/lower IEEE double precision number

耗尽温柔 提交于 2019-11-27 14:37:38
I am doing high precision scientific computations. In looking for the best representation of various effects, I keep coming up with reasons to want to get the next higher (or lower) double precision number available. Essentially, what I want to do is add one to the least significant bit in the internal representation of a double. The difficulty is that the IEEE format is not totally uniform. If one were to use low-level code and actually add one to the least significant bit, the resulting format might not be the next available double. It might, for instance, be a special case number such as

Status of __STDC_IEC_559__ with modern C compilers

左心房为你撑大大i 提交于 2019-11-27 14:35:43
C99 added a macro __STDC_IEC_559__ which can be used to test if a compiler and standard library conform to the ISO/IEC/IEEE 60559 (or IEEE 754) standard. According to the answers for this question how-to-check-that-ieee-754-single-precision-32-bit-floating-point-representation most C compilers don't set the preprocessor macro __STDC_IEC_559__ . According to GCC's documentation it does not define __STDC_IEC_559__ . I tested this with GCC 4.9.2 and Clang 3.6.0 both using with glibc 2.21 using the following code. //test.c //#include <features.h> int main(void) { #if defined ( __STDC_IEC_559__ ) /

Maximum number of decimal digits that can affect a double

天大地大妈咪最大 提交于 2019-11-27 14:30:59
Consider decimal representations of the form d1.d2d3d4d5...dnExxx where xxx is an arbitrary exponent and both d1 and dn are nonzero. Is the maximum n known such that there exists a decimal representation d1.d2d3d4d5...dnExxx such that the interval (d1.d2d3d4d5...dnExxx, d1.d2d3d4d5...((dn)+1)Exxx) contains an IEEE 754 double? n should be at least 17. The question is how much above 17. This number n has something to do with the number of digits that it is enough to consider in a decimal-to-double conversion such as strtod() . I looked at the source code for David M. Gay's implementation hoping