I need to reverse a given floating point number like say 45.687 to 786.54. This must be done in C. and the constraints are U are not supposed to use any inbuilt string functions.
what u mean by reverse?
when I give U a number as 67.89 i need to get the output as 98.76...???
You can just use mathematical manipulations to isolate each place value. Although if you want to actually want to avoid floating point manipulations (using the FPU) you would need to look up the IEEE encoding for floating point numbers (assuming this is the model used on the target architecture).
yea alchemista is right, u can extrac the digits one my one and make the reverse, using modulo and / operations. Playing with bit its really hard imo. First off flotating point are stored in a normalized way, no as u see them, an u got an exponent and mantise, u will have really hard math there. As string seems easy, swap first with last, second with penultimate an so one.
Whether could we get individual numbers in a floating point value...?? is that possible?? in integer we could do it with a modulo by 10 and then divide by 10... but how to go with floating point number?? any idea?
There is fmod (floating point mod)
well multiply by 10 o more (100, 1000,...)
a lol didnt know that, isnt that form assembly?
standard c library
its part of the FPU on most archs I think
yea i programmed a year a go a mini compiler and used x86 Intel syntax and i remeber there was an instruction for that, if i recall well xD
Hmmm, fine guys thanks a lot :) :) will use these... :) do look over the other q, when U have time... :)
I would not reverse a floating point number using complicated arithmetic. I would convert the number to a fixed point string, reverse the string, and then convert back to a float.
@drjefferson well the challenge is, we are not supposed to use any inbuilt string functions and we need to code only in c
Join our real-time social learning platform and learn together with your friends!