?
Solved

help me!

Posted on 1999-11-07
6
Medium Priority
?
306 Views
Last Modified: 2010-04-01
I can't find the function 'trunc()' 's lib in borland c++ builder ,please tell me the lib name.

thank you!
0
Comment
Question by:afeng
6 Comments
 
LVL 4

Accepted Solution

by:
nils pipenbrinck earned 150 total points
ID: 2189425
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
 
LVL 22

Expert Comment

by:nietod
ID: 2189440
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
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2190525
Keep in mind that floor finds the largest integer not greater than x. Thus floor(-4.5) == -5
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 85

Expert Comment

by:ozo
ID: 2190552
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
 
LVL 4

Expert Comment

by:nils pipenbrinck
ID: 2191550
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
 
LVL 85

Expert Comment

by:ozo
ID: 2191675
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question