ieee-754

How to convert a floating point number to its binary representation (IEEE 754) in Javascript?

What's the easiest way to convert a floating point number to its binary representation in Javascript? (e.g. 1.0 -> 0x3F800000). I have tried to do it manually, and this works to some extent (with usual numbers), but it fails for very big or very small numbers (no range checking) and for special cases (NaN, infinity, etc.): function flo...

Do-s and Don't-s for floating point arithmetic?

What are some good do-s and don't-s for floating point arithmetic (IEEE754 in case there's confusion) to ensure good numerical stability and high accuracy in your results? I know a few like don't subtract quantities of similar magnitude, but I'm curious what other good rules are out there. ...

Why does this loop never end?

Possible Duplicate: problem in comparing double values in C# I've read it elsewhere, but really forget the answer so I ask here again. This loop seems never end regardless you code it in any language (I test it in C#, C++, Java...): double d = 2.0; while(d != 0.0){ d = d - 0.2; } ...

Decimal Conversion Ranges in the IEEE 754 Specification (Binary Floating-Point Arithmetic)

Table 2 in section 5.6 on the bottom of page 11 of the IEEE 754 specification lists the ranges of decimal values for which decimal to binary floating-point conversion must be performed. The ranges of exponents don't make sense to me. For example, for double-precision, the table says the maximum decimal value eligible to be converted is (...

For any finite floating point value, is it guaranteed that x - x == 0?

Floating point values are inexact, which is why we should rarely use strict numerical equality in comparisons. For example, in Java this prints false (as seen on ideone.com): System.out.println(.1 + .2 == .3); // false Usually the correct way to compare results of floating point calculations is to see if the absolute difference agains...

Scheme: Using only R6RS, how do I determine a flonum's mantissa and exponent

Is this possible to extract mantissa and exponent from a float in major R6RS Scheme implementations so that: v = f x b^e f - mantissa b - base e - exponent For example: 3.14 = 0.785 x 2^2 If it's not supported, I'd like to have access to flonum's (IEEE 754) bits directly to approach the problem of extracting the above values, but I'v...

Retrieving the actual binary value of a JavaScript number value?

In JavaScript, for a given property containing a Number value, is it possible to retrieve the actual binary value - the 64 bits representing the value. var x = 13; What 64 bits are stored in the memory location that x points to? I know that there are IEEE 754 converters out there. But is it possible to retrieve the actual live binary ...

Encoding and decoding IEEE 754 floats in JavaScript

I need to encode and decode IEEE 754 floats and doubles from binary in node.js to parse a network protocol. Are there any existing libraries that do this, or do I have to read the spec and implement it myself? Or should I write a C module to do it? ...

Decimal to floating point

If I wanted to convert a number Ex. 32.24x10^5 to IEEE 754 standard BY HAND how would I do it? ...

Packing 32bit floats into 30 bits (c++)

Hi all. Here are the goals I'm trying to achieve: I need to pack 32 bit IEEE floats into 30 bits. I want to do this by decreasing the size of mantissa by 2 bits. The operation itself should be as fast as possible. I'm aware that some precision will be lost, and this is acceptable. It would be an advantage, if this operation would not r...

Algorithm or code for float to base 2 scientific notation (IEEE 32 bits) in C++?

I'm taking in a float as input, and then outputting its equivalent representation in base 2 scientific notation. This is in IEEE 32 bits with: 31 sign bit, 23-30 exponent (with 127 offset), 0-22 mantissa (with implicit leading 1). One of the conditions which I'm not exactly sure the meaning of is "Your mantissa should have the implicit ...

Why do we have "is not a Number" (isNan) functions?

Many languages have an isNaN() function. I am asking myself: why check for not being a number? Is the reason purely logical or is it faster to check for not a number instead of is a number? Note that this is a pure question of understanding. I know that I can negate isNaN() to achieve an isNumber() function for example. However I am se...

Convert IEEE float hex to decimal?

IF I have a IEEE float hex 42F6E979, how do I convert it to decimal? I believe the decimal representation is = 123.456001 ...

Why don't operations on double-precision values give expected results?

System.out.println(2.14656); 2.14656 System.out.println(2.14656%2); 0.14656000000000002 WTF? ...

How to alter double by its smallest increment

Is something broken or I fail to understand what is happening? static String getRealBinary(double val) { long tmp = Double.doubleToLongBits(val); StringBuilder sb = new StringBuilder(); for (long n = 64; --n > 0; tmp >>= 1) if ((tmp & 1) == 0) sb.insert(0, ('0')); else sb.insert(0, (...

binary sequences and floating point IEEE 754 what???

I HAVE NO IDEA what this means please help anyone? With 32-bit binary sequences x = 0100 0110 1101 1000 0000 0000 0000 0000 and y = 1011 1110 1110 0000 0000 0000 0000 0000 representing single precision IEEE 754 floating point numbers, perform following arithmetics and show the results in both normalized format and IEEE 754 sin...

define double constant as hexadecimal?

Hi, I would like to have the closest number below 1.0 as a floating point. By reading wikipedia's article on IEEE-745 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 th...

Convert Between Floating Point Standards

I am trying to convert an IEEE based floating point number to a MIL-STD 1750A floating point number. I have attached the specification for both: I understand how to decompose the floating point 12.375 in IEEE format as per the example on wikipedia. However, I'm not sure if my interpretation of the MIL-STD is correct. 12.375 = (12)b...

How does MySQL handle exact IEEE 754 representations?

Is there a way to load exact octal, hex or binary representations of IEEE 754 floats (as text) into a MySQL table using the correct single- or double-precision data type? E.g. the number pi written as 1078530011 or 40490fdb (single-precision). Preferably with LOAD DATA INFILE/mysqlimport, in the interests of speed... ...

Emulating IBM floating point multiplication/addition in VBA

I am attempting to emulate a (no longer existing) mainframe report generator in an Access 2003 or Access 2010 environment. The data it generates must match exactly with paper reports from the early 70s. Unfortunately, the earliest years data were run on hardware that used IBM floating point representation instead of IEEE. With the help o...