Re: [Math] sin(), cos() not working? What special magic must I use to summon their powers?
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:cc:message-id:from:to :in-reply-to:content-type:mime-version:subject:date:references :x-mailer; bh=a3s5Rl0eN+j00vQU972N4VeA8Ak/5K6Vb7hF/3ke/0U=; b=tZJG9z7AzO5NwYg/KM8OzsULchvkZi9OlWZ8L25P3S6ZRFRauqUn8Fqj8M0GBDOXgU AAOifXNTbF4Dn/c04YzvlLa0maom8VLrSnvM4/dWwyNBLwrAZA13abVCZYXQbmEzvbqP QHfyXtzE/UD3dNqrxJOhSqZMGHJubK7AjX+JE= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type:mime-version:subject :date:references:x-mailer; b=jA0JSYDgSm8t+T5prPmyKM19O/hIhQacfWb1Q6xBO32eog1q7LjhAAAxE8G23Q3kZ+ UPUlL77gOJXdbaCGdSiTyHpRAfYlv+7ypT74FyBs+Xd6D9NvQsYF7oqtWI7gPBR8KjW2 W4slez7Tnx5GqoRfYWxNklU15pCVtO8/B/BV0= On Sep 30, 2008, at 07:29 , Michael Robinson wrote: Hello, I am trying to convert the following from Javascript to Cocoa ObjC: return retVal; This is what I've got: float retVal; retVal = cornerSize*(1-cos(asin(i/cornerSize))); return (int)retVal; double retVal; retVal = cornerSize*(1-cos(asin(i/cornerSize))); return lround(retVal); Jason _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.apple... This email sent to site_archiver@lists.apple.com var retVal = Math.round(cornerSize*(1-Math.cos(Math.asin(i/ cornerSize)))); Now retVal _must_ be an int, because the value is used as a margin attribute ("rounding" corners of divs). 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. 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? This is happening because the function is returning a value less than zero and your integer is getting truncated. You want to do something like this: (this function should return a long integer--see the man page for lround for other options) smime.p7s
participants (1)
-
Jason Coco