ieee-754

Bogus parsing/eval of complex literals

 ̄綄美尐妖づ 提交于 2020-01-06 03:06:08
问题 When evaluating complex numbers, python likes to fiddle the signs. >>> -0j (-0-0j) >>> (-0-0j) 0j Why? nb: I noticed it when reading this question. 回答1: The issue here is that Python doesn't parse complex numbers such as (-0-0j) as literals, they are actually parsed as an expression: >>> import ast >>> ast.dump(ast.parse('(-0-0j)')) 'Module(body=[Expr(value=BinOp(left=UnaryOp(op=USub(), operand=Num(n=0)), op=Sub(), right=Num(n=0j)))])' So, this is not a complex literal but a reflected

Is IEEE 754 floating point representation wasting memory?

爷,独闯天下 提交于 2020-01-05 04:35:29
问题 I always thought that there are 2^64 different fractional values that can be stored by a variable of type double. (Each bit can have either 1 or 0 as value and so 2^64 different values). Recently I came to know that NaN (not a number) has a representation in which exponent part is 11111111111 and significand part is any non-zero value. Instead, if it were like the representation is NaN if exponent part is 11111111111 and significand part is 111111......(52 times) ? Won't this allow us to

Gradual underflow and denormalized numbers in IEEE

时光毁灭记忆、已成空白 提交于 2020-01-05 04:08:17
问题 I was reading about floating-point representation and underflow/overflow and I ecnountered something interesting - gradual underflow. As I understand gradual underflow means that the result of, for example substraction x-y is so small that it could be flushed to 0 but floating-point system produces number that is smaller then UFL. Everywhere I read that it is made by losing some precission, it means that some bits of mantissa goes to exponent so we can have smaller exponent? 回答1: Effectively

Java: convert floating point binary to floating point decimal

你离开我真会死。 提交于 2020-01-04 07:27:07
问题 I want to convert a string representing the mantissa portion of a IEEE754 double. Cannot find if there is such a conversion method in Java, in order to avoid manually adding 1 + 1/2 + 1/4 + 1/8 etc. |0100000011001010000111110000000000000000000000000000000000000000 --> 13374 in IEEE754 |------------1010000111110000000000000000000000000000000000000000 --> mantissa part | 1.1010000111110000000000000000000000000000000000000000 --> restoring fixed value 1 String s = "1

IEEE 754, division by zero

给你一囗甜甜゛ 提交于 2020-01-04 05:12:07
问题 I know in standard IEEE 754 division by zero is allowed. I want to know how it's represented in binary. For example, 0.25 in decimal is 0 01111101 00000000000000000000000 in binary. What about 5.0/0.0 or 0.0/0.0 do they have represenation in binary, and are they same? Thanks. 回答1: When you divide a finite number by zero you'll get an infinity with the sign of the number you tried to divide. So 5.0/0.0 is +inf but 0.0/0.0 returns something called a QNaN indefinite. Let’s say we are dividing

define double constant as hexadecimal?

∥☆過路亽.° 提交于 2020-01-03 11:24:58
问题 I would like to have the closest number below 1.0 as a floating point. By reading wikipedia's article on IEEE-754 I have managed to find out that the binary representation for 1.0 is 3FF0000000000000 , so the closest double value is actually 0x3FEFFFFFFFFFFFFF . The only way I know of to initialize a double with this binary data is this: double a; *((unsigned*)(&a) + 1) = 0x3FEFFFFF; *((unsigned*)(&a) + 0) = 0xFFFFFFFF; Which is rather cumbersome to use. Is there any better way to define this

define double constant as hexadecimal?

点点圈 提交于 2020-01-03 11:24:15
问题 I would like to have the closest number below 1.0 as a floating point. By reading wikipedia's article on IEEE-754 I have managed to find out that the binary representation for 1.0 is 3FF0000000000000 , so the closest double value is actually 0x3FEFFFFFFFFFFFFF . The only way I know of to initialize a double with this binary data is this: double a; *((unsigned*)(&a) + 1) = 0x3FEFFFFF; *((unsigned*)(&a) + 0) = 0xFFFFFFFF; Which is rather cumbersome to use. Is there any better way to define this

How does the number 0 look like in binary float format?

≡放荡痞女 提交于 2020-01-03 05:48:06
问题 The float format (IEEE) has 32 bits. First bit for the sign, after that 8 bits for a biased exponent and after that another 23 bits for the mantissa. In this mantissa is the first 1 (is always 1) always hidden which leads me to my question: how does the number 0 look like in this format? because if the exponents 0 the number will always be 1. plus the mantissa is always minimum 1 right? If they are only zeros in the mantissa it will count as '1.0'... I really don't get this. 回答1: Wikipedia

How do I quickly calculate a large positive, or negative, power of 2 in Java?

柔情痞子 提交于 2020-01-03 04:49:13
问题 I want to calculate powers of two larger than 2 62 , so I must store the result in a double and can't use the (1L << exp) trick. I also want to store fractions representing negative powers of two. 回答1: Java provides java.lang.Math.scalb(float f, int scaleFactor) for this. It multiplies f by 2 scaleFactor . 回答2: Since the IEEE 754 standard specifies a hidden bit, you can simply leave the 52-bit significand portion as 0 and only need to change the exponent portion, which is a biased unsigned

IEEE - 754 - find signbit, exponent, frac, normalized, etc

爷,独闯天下 提交于 2020-01-01 18:54:26
问题 I am taking in a 8 digit hexadecimal number as an IEEE 754 bit floating point number and i want to print information about that number( signbit, expbits, fractbits, normalized, denormalized, infinity, zero, NAN) floating point should be a single. I read up on bit shifting, and i think this is how i am suppose to do it?. however, i am not 100% sure. I understand that the sign bit is found in the left most position of the number. which indicates positive or negative. How much do i shift it to