Questions tagged [floating-point-conversion]

Anything related to converting a floating point number to and from other representations.

290 questions
2
votes
3 answers

Converting a float to int

I'm have this assignment where you have to get an input of type float from the user which represents a value in dollars for example 4.05 so I want to convert this float to an int such that it becomes in cents so the value of the int should be 405 ,…
user862460
2
votes
2 answers

Convert number From Excel cell to IEEE 754 Hex format

Recently I have been wrestling with Excel due to the 15 significant digits display limit for a number. I have been looking for a way to display the IEEE 754 format of a value contained in a Excel cell (since they are documented to work that…
2
votes
3 answers

How could you divide an IEEE754 64-bit double by 1000 on a platform only supporting 32-bit float?

I've got an electricity meter connected to a DCS (distributed control system) by PROFIBUS. The meter (Siemens Sentron PAC3200) supplies its count as an IEEE 754 double in Wh (watt-hours). Also, the counter overflows at 1.0e12 Wh or 1,000 GWh.…
2
votes
3 answers

Python Pandas - how to convert string HH:MM:SS.mmm to float sss.ms?

I would like to convert string value HH:MM:SS.mmm to float value sec.milliseconds for arithmetic calculations. Is there a direct way to do this as currently I am doing it via split string function and it is a very tedious process. Dataframe looks…
2
votes
2 answers

Floating Point Addition / Multiplication / Division

I was doing some homework problems from my textbook and had a few questions on floating point rounding / precision for certain arithmetic operations. If I have casted doubles from an int like so: int x = random(); double dx = (double) x; And…
cheng
  • 1,264
  • 2
  • 18
  • 41
2
votes
1 answer

Why floating point comparisons gives different outputs on different compiler?

I was reading this. It contains following C program. #include int main() { float x = 0.1; if (x == 0.1) printf("IF"); else if (x == 0.1f) printf("ELSE IF"); else printf("ELSE"); } The article says…
Destructor
  • 14,123
  • 11
  • 61
  • 126
2
votes
1 answer

go - encoding unsigned 16 bit float in binary

In Go, how can I encode a float into a byte array as a 16 bit unsigned float with 11 explicit bits of mantissa and 5 bits of explicit exponent? There doesn't seem to be a clean way to do it. The only thing I can think of is encoding it as in Convert…
2
votes
1 answer

Why does the compiler parse a floating point number in a source file differently than at runtime?

I've been working on some Rust projects lately to learn the language and have some fun. I am writing something similar to libconfig in Rust, using the peg crate to generate my parser. For the last hour, I've been fighting with a weird bug where some…
2
votes
1 answer

Converting raw binary to float printing 0 for small values

I am trying to read 2 32 bit values ( assuming they are ieee 745 single precision float values ) and comparing them to check if they are equal using following snippet, #include #include void main(){ int a; int b; …
2
votes
3 answers

Random data with JMH Java microbenchmark testing floating point printing

I'm writing a JMH microbenchmark for floating point printing code I wrote. I'm not overly concerned about the exact performance yet, but getting the benchmark code correct. I want to loop over some randomly generate data, so I make some static…
2
votes
1 answer

How to convert Java double to byte[], and byte[] to double (IEEE 754 double-precision binary floating-point format)

I have 3 methods (1 functional (double to byte[]), and one returning unexpected value (byte[] to double), and 1 method that is functional but performs to many operations to use Hex to double)). Performance is the utmost importance, so if you have…
Aaron Sims
  • 23
  • 1
  • 3
2
votes
2 answers

C: Better method for rounding down double to int

My question is; is there a functional difference between rounding a double down to an int via roundedInt = (int)unRoundedDouble and roundedInt = (int)(floor(unRoundedDouble)) ? I've seen the latter used in code, and thought that maybe it's for…
BigBadWolf
  • 603
  • 2
  • 8
  • 17
2
votes
1 answer

Python2: Convert a set of floats to a string

Question The goal is to find a simple way for converting a set of data to a string. Maybe I am too newby but I found nothing about conversion from a set to string. A similar question (Numpy converting array from float to strings) did not help me a…
strpeter
  • 2,562
  • 3
  • 27
  • 48
2
votes
2 answers

Float24 (24 bit floating point) to Hex?

I'm using float 24 bit to store a floating point value in a compiler MRK III from NXP. It stores the 24 bit float value as 3 byte Hex in Data memory. Now when I'm using IEEE 754 float point conversion to retrieve the number back from binary to…
2
votes
4 answers

Extracting significand and exponent for base-10 representation from decimal formatted string

I am looking for an efficient Python implementation of a function that takes a decimal formatted string, e.g. 2.05000 200 0.012 and returns a tuple of two integers representing the significand and exponent of the input in base-10 floating point…
ARF
  • 7,420
  • 8
  • 45
  • 72