• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[Math] sin(), cos() not working? What special magic must I use to summon their powers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Math] sin(), cos() not working? What special magic must I use to summon their powers?


  • Subject: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
  • From: Michael Robinson <email@hidden>
  • Date: Wed, 1 Oct 2008 00:29:32 +1300

Hello,

I am trying to convert the following from Javascript to Cocoa ObjC:

var retVal = Math.round(cornerSize*(1-Math.cos(Math.asin(i/ cornerSize))));

return retVal;

Now retVal _must_ be an int, because the value is used as a margin attribute ("rounding" corners of divs).

This is what I've got:

Variables i, cornerSize are passed to the function from a for loop. i being the counter for the loop, cornerSize being the size of corner desired by the user.

	float retVal;

	retVal = cornerSize*(1-cos(asin(i/cornerSize)));

	return (int)retVal;

Obviously, I'm no whiz at ObjC, and the fact that this keeps return '0' has got me stumped.

At first I thought it was some stupid mistake I made translating the formula, but I tested a few things and now I'm not so sure.

sin(90); returns 0 as well. When I use Apple's Calculator and ask it to tell me the result of sin(90), it gives me 1.

What what whaaaaat?

Do I need to import something for this to work? Am I not tilting my head in the correct direction while typing my code?

I'm pretty stuck here, and would appreciate any help.

Thanks

Mike



-	-	-
Errors have occurred.
We won't tell you where or why.
Lazy programmers.
-	-	-
Charlie Gibbs

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
      • From: Manfred Schwind <email@hidden>
    • Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
      • From: Graham Cox <email@hidden>
    • Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
      • From: Jason Coco <email@hidden>
    • Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
      • From: Memo Akten <email@hidden>
  • Prev by Date: re: NSManagedObject subclass accessor pattern mystery?
  • Next by Date: Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
  • Previous by thread: Re: ld: duplicate symbol
  • Next by thread: Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
  • Index(es):
    • Date
    • Thread