dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Function always returns zero

  1. #1
    Join Date
    Jul 2007
    Posts
    33

    Function always returns zero

    Can anyone tell me why this function always returns zero?

    double func(double n)
    {return (1/6)*(sin(sqrt(
    (pow(n*(a[0]-c[0]),2)+pow(n*(a[1]-c[1]),2)+pow(n*(a[2]-c[2]),2))+
    (2*n*(((s[0]-(a[0]*n)+(b[0]*n)-b[0])*(a[0]-c[0]))+
    ((s[1]-(a[1]*n)+(b[1]*n)-b[1])*(a[1]-c[1]))+
    ((s[2]-(a[2]*n)+(b[2]*n)-b[2])*(a[2]-c[2]))))+
    (pow(s[0]-(a[0]*n)+(b[0]*n)-b[0],2)+pow(s[1]-(a[1]*n)+(b[1]*n)-b[1],2)+pow(s[2]-(a[2]*n)+(b[2]*n)-b[2],2)))+
    sqrt(
    (pow(n*(a[0]-c[0]),2)+pow(n*(a[1]-c[1]),2)+pow(n*(a[2]-c[2]),2))+
    (2*n*(((p[0]-(a[0]*n)+(b[0]*n)-b[0])*(a[0]-c[0]))+
    ((p[1]-(a[1]*n)+(b[1]*n)-b[1])*(a[1]-c[1]))+
    ((p[2]-(a[2]*n)+(b[2]*n)-b[2])*(a[2]-c[2]))))+
    (pow(p[0]-(a[0]*n)+(b[0]*n)-b[0],2)+pow(p[1]-(a[1]*n)+(b[1]*n)-b[1],2)+pow(p[2]-(a[2]*n)+(b[2]*n)-b[2],2))))+

    sin(sqrt
    (pow(s[0]-(a[0]*n)+(b[0]*n)-b[0],2)+pow(s[1]-(a[1]*n)+(b[1]*n)-b[1],2)+pow(s[2]-(a[2]*n)+(b[2]*n)-b[2],2))+
    sqrt
    (pow(p[0]-(a[0]*n)+(b[0]*n)-b[0],2)+pow(p[1]-(a[1]*n)+(b[1]*n)-b[1],2)+pow(p[2]-(a[2]*n)+(b[2]*n)-b[2],2)))+

    4*sin(sqrt(
    (0.25*(pow(n*(a[0]-c[0]),2)+pow(n*(a[1]-c[1]),2)+pow(n*(a[2]-c[2]),2)))+
    (n*(((s[0]-(a[0]*n)+(b[0]*n)-b[0])*(a[0]-c[0]))+
    ((s[1]-(a[1]*n)+(b[1]*n)-b[1])*(a[1]-c[1]))+
    ((s[2]-(a[2]*n)+(b[2]*n)-b[2])*(a[2]-c[2]))))+
    (pow(s[0]-(a[0]*n)+(b[0]*n)-b[0],2)+pow(s[1]-(a[1]*n)+(b[1]*n)-b[1],2)+pow(s[2]-(a[2]*n)+(b[2]*n)-b[2],2)))+
    sqrt(
    (0.25*(pow(n*(a[0]-c[0]),2)+pow(n*(a[1]-c[1]),2)+pow(n*(a[2]-c[2]),2)))+
    (n*(((p[0]-(a[0]*n)+(b[0]*n)-b[0])*(a[0]-c[0]))+
    ((p[1]-(a[1]*n)+(b[1]*n)-b[1])*(a[1]-c[1]))+
    ((p[2]-(a[2]*n)+(b[2]*n)-b[2])*(a[2]-c[2]))))+
    (pow(p[0]-(a[0]*n)+(b[0]*n)-b[0],2)+pow(p[1]-(a[1]*n)+(b[1]*n)-b[1],2)+pow(p[2]-(a[2]*n)+(b[2]*n)-b[2],2)))));}

    Thank you.
    Andy

  2. #2
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Function always returns zero

    Come on... Are you kidding??
    Guess not.
    Why don't you tell us when you find out?

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Function always returns zero

    Code:
    return (1/6)* ...
    Integer math of 1 divided by 6 yields zero. Try
    Code:
    return (1.0/6.0)* ...
    Mike

  4. #4
    Join Date
    Jul 2007
    Posts
    33

    Re: Function always returns zero

    That did it!
    Thanks a lot.
    Andy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)