473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

float to demoted integer conversion

i want to make program of : Read float, and convert this in to demoted integer without using int.
It is by using the reverse the IEEE float format.
If you have any sollution please give me.
Apr 19 '10 #1
6 2739
donbock
2,426 Expert 2GB
So you want to explicitly decode the bit pattern of a floating point number. You need to know how floating point numbers are encoded for your particular compiler. You need to know the endianness of your compiler. These two things can vary from one compiler to another, so nobody can offer specific assistance until you make these determinations.

I wouldn't recommend doing this. I assume it is an assignment.
Apr 19 '10 #2
RedSon
5,000 Expert 4TB
I'm confused...

You want to take a float, convert it to an int, then put that int into a float?

So essentially you want to concatenate the floating point part of the float and just take the whole number? Or do you want the floor of the float?
Apr 19 '10 #3
donbock
2,426 Expert 2GB
@RedSon ... I believe he wants to write a floating point value into a union that overlays an integral array on top of the floating point type. Then he wants to parse the implementation-dependent encoding of that floating point value in the array in order to explicitly extract the integer portion of the value.

Nobody would do it this way in the real world (unless they were writing a compiler), so this must be a homework assignment to teach floating point encoding to the students.
Apr 19 '10 #4
RedSon
5,000 Expert 4TB
Ahh I see,

So here:

Take the floor of the float, that becomes your integral part then you subtract the floor from the float and that becomes your floating point part. If this is an assignment then you don't need to worry about speed (or really accuracy much). If your professor is asking you to do this at the bit level then we are going to need more information.
Apr 19 '10 #5
donbock
2,426 Expert 2GB
Function modf() would be a better choice than floor() and subtraction. However, my impression is that he has to do this at the bit level.
Apr 19 '10 #6
RedSon
5,000 Expert 4TB
True, but I'm trying to make it like a step by step thing, really brute force for a person who is learning the language.

But either way.

I'm surprised a professor would assign a task like this unless they were using some kind of educational compiler or some simulated platform environment.
Apr 19 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Richard Thrasher | last post by:
Writing my very first C# program, I found what appears to be a compiler error. The statement int temp = (int)(100 * 36.41); assigns the value 3640 to temp. I've tried this code with various...
1
by: Gabest | last post by:
Running this piece of code while having the sse optimization turned on (vcnet2003), something really strange happens I cannot explain. Without sse it is giving me the right results. float f =...
20
by: Trond Valen | last post by:
Hi! Stupid atof, it returns 0.0 when it tries to parse something like "fish". So I don't know whether the number was really 0 or a string that couldn't be parsed. Is there a better way to do...
4
by: Geky | last post by:
Why when I multiply a float , for example X10, and than convert it as an integer the new value is changed? Example: float fl = 1.8 int x; x = int(fl * 10);
13
by: mishj | last post by:
Someone else on here had the same issue as I have but the response he got didnt solve my problem so I hope someone can help me (for some reason I was unable to reply on the same thread as the...
15
by: Br | last post by:
Cint(3/2) = 2 (rounded up, I would have thought the answer would be 1) Cint(5/2) = 2 (rounded down) The Access help says Cint() rounds to the nearest even number, but why?? Do I need to...
15
by: k3n3dy | last post by:
Hello everybody, I would like to ask anybody to help me understand what should be done exactly with this Problem. I have provided what I have up to now, although it is not quite accurate. Create...
1
by: iulian.ilea | last post by:
I have this functions, c3 and c2 that computes and return a float number. The problem is that wen I pass the result of c2 (float number) to c3(), in function apears to be an integer. Ex.:...
1
by: YouPoP | last post by:
For a reason i don't know, if i convert a float to a cstring, it does not convert to an exact value for all values except round numbers or 1/2 numbers; the following code (used to convert and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.