Results 1 to 7 of 7

Thread: explicit cast building own math library

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default explicit cast building own math library

    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:
    Qt Code:
    1. int IDiv( int a, int b ) {
    2. assert (b != 0);
    3. return (int) ((float) a / (float) b);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Is it beautiful?
    Willing avoid the C/C++ math library, now I'm wonder how to do the rest of a division.....
    Suggests?
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: explicit cast building own math library

    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.
    There are 10 people in the world. Those who understand binary and those who don't.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: explicit cast building own math library

    Quote Originally Posted by Thomas View Post
    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?
    Quote Originally Posted by Thomas View Post
    Comment on the current code: do not use C-style casts.
    And If I used a C compiler?
    Regards

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: explicit cast building own math library

    And If I used a C compiler?
    Why do you ask rhetorical questions?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: explicit cast building own math library

    Quote Originally Posted by mickey View Post
    If used math.h, what does remain to do?
    I can give you dozens of tasks if you have too much free time

  6. #6
    Join Date
    Jan 2006
    Location
    Socorro, NM, USA
    Posts
    29
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: explicit cast building own math library

    Quote Originally Posted by wysota View Post
    I can give you dozens of tasks if you have too much free time
    Good one!
    There are 10 people in the world. Those who understand binary and those who don't.

  7. #7
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Thumbs up Re: explicit cast building own math library

    I have some work like Wysota; if you want to share!!!
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.