Standart VHDL function that rounds down numbers

Status
Not open for further replies.

shaiko

Advanced Member level 5
Joined
Aug 20, 2011
Messages
2,644
Helped
303
Reputation
608
Reaction score
297
Trophy points
1,363
Activity points
18,302
Hello,

Is there a standard VHDL function that accepts real numbers and rounds them down?
For example:

signal x : real
x <= 14.6 ;

A function that when applied on X will return 14.0
 

function FLOOR (X : real ) return real;

There is also a corresponding CEIL function
 
and the trunc function too.

x <= trunc(14.6);
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
What's the functional deference between "floor" and "trunc"?
 

without looking at the actual package body the fucntion descriptions seems to indicate semantically different but identical behavior.
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Presumably floor() and trunc() will give different results for negative numbers.

floor(-42.42) = -43

trunc(-42.42) = -42
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Different result for negatives and same result for positives?
 

Yes. From the man pages:

floor(x)
... return the largest integral value that is not greater than x.

trunc(x)
... round x to the nearest integer not larger in absolute value.
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…