PDA

View Full Version : explicit cast building own math library



mickey
4th February 2008, 14:40
Hello,
I'd like build my own math class library (without using cmath or other). I'm doing the division:
At the moment I'm doing operation between integer and every method ust return an integer; IDiv return the integer part if it cannot do the division; to do this I thought to exploit (int); see below:


int IDiv( int a, int b ) {
assert (b != 0);
return (int) ((float) a / (float) b);
}
Is it beautiful?
Willing avoid the C/C++ math library, now I'm wonder how to do the rest of a division.....
Suggests?

Thomas
5th February 2008, 17:20
First question: why do you want to avoid the C-math library? There is nothing wrong with it.

Second question: are you are looking for floating point math routines for non-FP CPUs? If yes, have a look at http://www.radiks.net/~rhuebner/mathlib.html.

Comment on the current code: do not use C-style casts.

mickey
6th February 2008, 17:44
First question: why do you want to avoid the C-math library? There is nothing wrong with it.

to do exercise. If used math.h, what does remain to do?


Comment on the current code: do not use C-style casts.
And If I used a C compiler?

marcel
6th February 2008, 17:51
And If I used a C compiler?

Why do you ask rhetorical questions?

wysota
6th February 2008, 19:45
If used math.h, what does remain to do?

I can give you dozens of tasks if you have too much free time :)

Thomas
6th February 2008, 23:30
I can give you dozens of tasks if you have too much free time :)

Good one! :p

ashukla
7th February 2008, 05:48
I have some work like Wysota; if you want to share!!!:)