Questions tagged [floating-point-conversion]

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

290 questions
8
votes
6 answers

Convert float to its binary representation (using MemoryStream?)

I'd like to convert a given float into its binary representation. I tried to write the float value into a MemoryStream, read this MemoryStream byte by byte and convert the bytes into their binary representation. But every attempt failed. "Can't…
Cubi73
  • 1,891
  • 3
  • 31
  • 52
8
votes
6 answers

Writing an image with floating point values

My code reads an RGB image, processing it to produce floating-point results. How can I write these values as an image, maintaining these floating-point values, in Matlab 7.6.0 (R2008a)?
7
votes
4 answers

Understanding casts from integer to float

Could someone explain this weird looking output on a 32 bit machine? #include int main() { printf("16777217 as float is %.1f\n",(float)16777217); printf("16777219 as float is %.1f\n",(float)16777219); return 0; } Output 16777217…
7
votes
2 answers

problems in floating point comparison

void main() { float f = 0.98; if(f <= 0.98) printf("hi"); else printf("hello"); getch(); } I am getting this problem here.On using different floating point values of f i am getting different results. Why this is…
Adi
  • 163
  • 2
  • 4
  • 8
7
votes
3 answers

How to round a floating point number upto 3 digits after decimal point in bash

I am a new bash learner. I want to print the result of an expression given as input having 3 digits after decimal point with rounding if needed. I can use the following code, but it does not round. Say if I give 5+50*3/20 + (19*2)/7 as input for the…
7
votes
2 answers

Is there a standard C way to print floating-point values "perfectly" a la Dragon4?

Reading Here be dragons: advances in problems you didn’t even know you had I've noticed that they compare the new algorithm with the one used in glibc's printf: Grisu3 is about 5 times faster than the algorithm used by printf in GNU libc But at…
Ruslan
  • 18,162
  • 8
  • 67
  • 136
7
votes
2 answers

Converting Int to Float loses precision for large numbers in Swift

XCode 6.3.1 Swift 1.2 let value: Int = 220904525 let intmax = Int.max let float = Float(value) // Here is an error probably let intFromFloat = Int(float) let double = Double(value) println("intmax=\(intmax) value=\(value) float=\(float)…
7
votes
2 answers

C++ double to long long

If i write code in c++: long long d = 999999998.9999999994; cout<
pirate
  • 496
  • 6
  • 16
7
votes
1 answer

C# float precision

Can anyone please explain to me what's happening here: using System; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { object o = 1000000.123f; float f=…
7
votes
1 answer

Generate large number of unique random float32 numbers

I need to generate a binary file containing only unique random numbers, with single precision. The purpose is then to calculate the entropy of this file and use it with other datasets entropy to calculate a ratio entropy_file/entropy_randUnique.…
7
votes
1 answer

Why is IEEE-754 Floating Point not exchangable between platforms?

It has been asserted that (even accounting for byte endian-ness) IEEE754 floating point is not guaranteed to be exchangeable between platforms. So: Why, theoretically, is IEEE floating point not exchangeable between platforms? Are any of these…
Damien
  • 785
  • 3
  • 8
  • 18
7
votes
3 answers

In Lua, what is #INF and #IND?

I'm fairly new to Lua. While testing I discovered #INF/#IND. However, I can't find a good reference that explains it. What are #INF, #IND, and similar (such as negatives) and how do you generate and use them?
Nathan Goings
  • 1,145
  • 1
  • 15
  • 33
7
votes
3 answers

Convert signed IEEE 754 float to hexadecimal representation

I'm using a front-end of Lua which is unfortunately outdated, so I'm stuck with version 5.1 here, meaning the bit32 library is out of reach (which I probably could have used to convert this). So I'm wondering if anyone knows of a way I could…
user966939
  • 692
  • 8
  • 27
7
votes
3 answers

Convert scientific notation to decimal - python

How do I convert a scientific notation to floating point number? Here is an example of what I want to avoid: Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>…
pistal
  • 2,310
  • 13
  • 41
  • 65
7
votes
3 answers

Dividing 1/n always returns 0.0

I am trying to calculate p1=(1/1)*(1/2)*...*(1/n) but something is wrong and the printf gives me 0.000...0 #include int main(void) { int i,num; float p3; do { printf ("give number N>3 : \n" ); scanf( "%d",…
user1809300
  • 703
  • 4
  • 9
  • 17
1 2
3
19 20