help me!

I can't find the function 'trunc()' 's lib in borland c++ builder ,please tell me the lib name.

thank you!
afengAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nils pipenbrinckCommented:
I'm not sure.. but trunc is used to round from float to int, isn't it?

standard clib gives you two different rounding functions. they are called


  float floor (float) // round up
  float ceil  (float) // round down

(defined in math.h or float.h)

If you only want the whole part of a
float number you can cast it to an
integer. I think that's the best match
to the trunc function.

Hope you don't speak about truncation of files btw. If so I could take a look at stdio.h There is a function to do this, but I rarely need it.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
nils_pipenbrinck is right, there is no trunc() in standard C/C++.  I beleive there is one in Pascal, perhaps that is what you were thinking of.  The floor() function is the equivilant one, or just converting to int.
0
KangaRooCommented:
Keep in mind that floor finds the largest integer not greater than x. Thus floor(-4.5) == -5
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ozoCommented:
casting to an integral type will truncate, but the behavior is undefined if the value anoot be represented by the integral type.

modf (double value, double *iptr) will store the truncated value in *iptr
0
nils pipenbrinckCommented:
ozo. the behaviour of casting is not undefined.. the ansi c standard describes which rounding mode to use.

I'm absolutely sure about that.. the intel c++ compiler is the only compiler where you can disable this behaviour for a little extra speed.

nils
0
ozoCommented:
ANSI specifies that rounding mode used when casting to an integral type is truncation toward zero.
ANSI also syas that if the value of the integral part cannot br represented by the integral type, the behavior is undefined.
(thus floating values greater than ULONG_MAX are not portable)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.