Questions tagged [floating-point-conversion]

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

290 questions
0
votes
4 answers

How can I avoid this float number rounding issue in C++?

With below code, I get result "4.31 43099". double f = atof("4.31"); long ff = f * 10000L; std::cout << f << ' ' << ff << '\n'; If I change "double f" to "float f". I get expected result "4.31 43100". I am not sure if changing "double" to…
poordeveloper
  • 2,272
  • 1
  • 23
  • 36
0
votes
4 answers

Finding the tenth's place equivalent of an integer

How does one, computationally and dynamically, derive the 'ths' place equivalent of a whole integer? e.g.: 187 as 0.187 16 as 0.16 900041 as 0.900041 I understand one needs to compute the exact th's place. I know one trick is to turn the integer…
0
votes
2 answers

Converting between coordinate spaces SpriteKit

I have a node with the shape of a box in a scene. The shape node should have its own coordinate space, so if I declare a point at (100,100) in the nodes coordinate space and rotate the box pi/4 rad the point should change in the scenes coordinate…
Marcus
  • 97
  • 1
  • 13
0
votes
2 answers

value != float or value != int does not work

i'm trying to make a calculator that can do 5 processes which are to add, subtract, multiply, divide and square root values that users input. all of that i've done, but when trying to make the values != float and int, the error comes for when the…
pheonixkid
  • 101
  • 1
  • 5
0
votes
1 answer

how to do floating point arithmetic without using float

In our processor,float is not allowed(u32 or int data type is allowed).Implementation needs the floating point addition,how addition of two real numbers can be done without using float?
0
votes
1 answer

What is the best way to quantize a float to a byte

I have a single-precision float value, and no information about the distribution of the samples from which this value was generated, so I can't apply a sigmoid or perform some kind of normalization. Also, I know the value will always be…
Sau
  • 326
  • 2
  • 15
0
votes
1 answer

Floating Point division, floor, and when a simple C++ Change Computing program gets complex

Floating point division is causing a value that should be 1 to be .9999999 thus flooring it becomes 0 instead of 1 so the calculation for the required change is incorrect. What's the simplest way to deal with this? (Also if there's some sort of…
0
votes
2 answers

nesC: converting float number to integer

I want to make xor of an uint16 with a floating point number like the following: uint16_t a=20000; double r,x,xo; r=3.8; xo=.1; x=(int) r*xo*(1-xo); c=a^x; When I run the test the following error occurs: invalid operand to binary ^ How can I…
0
votes
1 answer

JavaScript Only FadeIn Function

fadeIn:function(speed,till){ speed = speed !== undefined ? speed : 400; speed = typeof speed === 'number' ? speed : speed == "slow" ? 600 : speed == "fast" ? 200 : speed !== 'slow' || speed!== 'fast' ? 400 : 400; var…
EasyBB
  • 6,176
  • 9
  • 47
  • 77
0
votes
1 answer

STM32F4 float to int conversion

On STM32F4 MCU I need to convert floating point numbers into integer. I have FP numbers as result from arm_pid_f32() function but later I need to update internal DAC's values which accept 12bit integer. I know that i will lose some "precision" but…
mikikg
  • 1,488
  • 1
  • 11
  • 23
0
votes
1 answer

Get Single constant to be the same as runtime

I tried the equivalent of Michael Meadows EDIT 2, but in VB.NET and got a different result. (Specifically both the Double and Decimal results were 600000.0238418580.) I have determined the difference is with the compile-time accuracy of a Single…
Mark Hurd
  • 10,665
  • 10
  • 68
  • 101
0
votes
2 answers

Float read as double

My code looks like #include #include int main (void) { float x1, x2, x3; float y1, y2, y3; float Cos0, i, j, k, innerProduct; float Xlength,…
0
votes
2 answers

Max Float Fraction

Platform: Linux 3.2.0 (Debian 7.0) Compiler: GCC 4.7.2 (Debian 4.7.2-5) I am trying to convert character strings into floats. I am aware that there are already functions that do this. I am only doing this for practice. My function works well with…
John Vulconshinz
  • 1,088
  • 4
  • 12
  • 29
0
votes
5 answers

float value condition

I worked out the following code and got a bizarre output. Can anyone explain how it works? main() { float a=0.8; float b=0.25; if(a==0.8) printf("HELLO") if(b==0.25) printf("WORLD") } And the output that I got is…
Aswin Murugesh
  • 10,831
  • 10
  • 40
  • 69
0
votes
2 answers

Printing a float with commas in C

Possible Duplicate: Output 1000000 as 1,000,000 and so on I have a float variable in the format xxxxxxxx.xx (Eg. 11526.99). I'd like to print it as 11,562.99 with a comma. How can I insert a comma in C?
Jw123
  • 57
  • 2
  • 3
  • 8