Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

float to fixed point conversion function

Status
Not open for further replies.

omara007

Advanced Member level 4
Joined
Jan 6, 2003
Messages
1,237
Helped
50
Reputation
102
Reaction score
16
Trophy points
1,318
Location
Cairo/Egypt
Activity points
9,716
guys ..

anyone has a function to convert real/float numbers to fixed point with a given precision ?

for example : I give the function this number : (0.5) as a first argument and in the second argument I give it (1) as the number of binary digits to the left of the binary point , and (2) in the third argument as the number of binary digits to the right of the binary point.
The return value will be (010)

if the function is called funcX => funcX(0.75,1,2) returns (011)
and so on ..

functions in matlab, vhdl, c are all welcomed ..
 

AA,

omara007 wrote:

I give it (1) as the number of binary digits to the left of the binary point , and (2) in the third argument as the number of binary digits to the right of the binary point.

I think it is meaning less to give the required bits to represent the digits left to the radix point. What if you passed a number not sufficient to represent the that number? Will it discard the least or most significant bits?

By the way this function can be easly done.

Regards,
Amr.
 

amraldo said:
I think it is meaning less to give the required bits to represent the digits left to the radix point. What if you passed a number not sufficient to represent the that number? Will it discard the least or most significant bits?

There are some concepts that you maybe missing like overflow .. saturation ..

The function can saturate to its ceiling .. or simply assert an overflow flag ..

If you are close to the hardware architecture , u wouldn't have said so. Simply becuase if you go for design, you will be restricted in certain vector length where u have to shrink your data to fit in or make some work arounds ..
 

AA,
omara007 wrote:
There are some concepts that you maybe missing like overflow .. saturation ..
Be sure that I do not miss these concepts. But you did not specify these requirements in ur original message. you said u will specify the required bit width, so the function should overcome all possible values permited by software or hardware, whatever.

also wrote:
you will be restricted in certain vector length where u have to shrink your data to fit in or make some work arounds ..

Functions with variable parameters cannot be synthesized, if you are targetting hardware. You can model them only.

Finally,
I am glad to help if necessary.

Regards,
Amr.
 

Plz check documentation for "round", "floor", "ceil" and "fix" in MATLAB.These are built-in functions there scripts are not availble
 

khubaibahmed said:
Plz check documentation for "round", "floor", "ceil" and "fix" in MATLAB.These are built-in functions there scripts are not availble

I know these functions and they don't convert to fixed point in binary format .. the 4 of them are completely rounding functions and has nothing to do with floating/fixed point things ..
 

omara007 wrote:
I know these functions and they don't convert to fixed point in binary format .. the 4 of them are completely rounding functions and has nothing to do with floating/fixed point things ..

U can use them & write ur conevrsion functions for the extracted parts.

Regards,
Amr.
 

guys ..
the problem is not at all in ceinling/flooring .. am asking about a float to fixed standard function available in any language .. no more no less ..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top