Skip to Content
Learning the iOS 4 SDK for JavaScript Programmers
book

Learning the iOS 4 SDK for JavaScript Programmers

by Danny Goodman
December 2010
Beginner to intermediate
320 pages
10h 3m
English
O'Reilly Media, Inc.
Content preview from Learning the iOS 4 SDK for JavaScript Programmers

Math Object Equivalents in C

The core JavaScript language has a static Math object, which features a number of methods and properties that act as constants. For example, if you want to determine the next lesser integer for a floating-point value, use the floor() method of the static Math object, as follows:

var floorValue = Math.floor(myValue);

The C language doesn’t have a dedicated object of that type. Instead, it implements a series of functions, which you can call directly in your statements. For example:

double floorValue = floor(myValue);

Table 7-3 lists the JavaScript Math object functions and the corresponding C functions. The standard C language offers far more variations of these functions (in the math.h and stdlib.h libraries automatically incorporated into every iOS app), offering differing levels of precision. For Table 7-3, I have chosen the versions that return values of the double data type. Also pay special attention to the required data type of values passed as arguments to the C functions.

Table 7-3. Math functions comparisons

JavaScript

Description

C/Objective-C

Math.abs(x)

Absolute value

double fabs(double x);

Math.acos(x)

Arc cosine

double acos(double x);

Math.asin(x)

Arc sine

double asin(double x);

Math.atan(x)

Arc tangent

double atan(double x);

Math.atan2(x, y)

Angle of polar coordinates

double atan2(double y, double x);

Math.ceil(x)

Next greater integer

double ceil(double x);

Math.cos(x)

Cosine

double cos(double x);

Math.exp(x)

Euler’s constant to xth power

double exp(double x);

Math.floor(x) ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

iOS SDK Programming A Beginners Guide

iOS SDK Programming A Beginners Guide

James Brannan, Blake Ward

Publisher Resources

ISBN: 9781449399078Errata Page