Objective-C applies to C mathematical functions

Source: Internet
Author: User
Tags mathematical constants mathematical functions
Reprinted: http://hi.baidu.com/delphi9527/blog/item/2f29650d1302f2306159f319.html

 

In actual workProgramIt is inevitable to use mathematical functions for calculation, such as the transformation from the geographic coordinates of the map program to the map coordinates. As an extension of ansi c, objective-C uses the C standard library header file <math. h> mathematical constant macros and mathematical functions defined in to implement basic mathematical computation operations, so you don't have to bother looking for corresponding functions and classes in the cocoa Foundation. Some common macros and mathematical functions are listed here. For more details, refer to the header file <math. h>.

Mathematical constants:
# Define m_e 2.71828182845904523536028747135266250 // E
# Define m_log2e 1.44269504088896340735992468100189214 // log 2e
# Define m_log10e 0.434294481903251827651128918916605082 // log 10E
# Define m_ln2 0.693147180559945309417232121458176568 // log E2
# Define m_ln10 2.30258509299404568401799145468436421 // log E10
# Define m_pi 3.14159265358979323846264338327950288 // pi
# Define m_pi_2 1.57079632679489661923132169163975144 // PI/2
# Define m_pi_4 0.785398163397448309615660845819875721 // PI/4
# Define m_0000pi 0.318309886183790671537767526745028724 // 1/PI
# Define m_2_pi 0.636619772367581343075535053490057448 // 2/PI
# Define m_2_sqrtpi 1.12837916709551257389615890312154517 // 2/SQRT (PI)
# Define m_sqrt2 1.41421356237309504880168872420969808 // SQRT (2)
# Define m_sqrt1_2 0.707106781186547524400844362104849039 // 1/SQRT (2)

Common functions:
// Exponential operation
Nslog (@ "%. F", POW (3, 2); // result 9
Nslog (@ "%. F", POW (3, 3); // result 27

// Square operation
Nslog (@ "%. F", SQRT (16); // Result 4
Nslog (@ "%. F", SQRT (81); // result 9

// Rounding up
Nslog (@ "res: %. F", Ceil (3.000000000001); // Result 4
Nslog (@ "res: %. F", Ceil (3.00); // result 3

// Drop-down
Nslog (@ "res: %. F", floor (3.000000000001); // result 3
Nslog (@ "res: %. F", floor (3.9999999); // result 3

// Rounding
Nslog (@ "res: %. F", round (3.5); // Result 4
Nslog (@ "res: %. F", round (3.46); // result 3
Nslog (@ "res: %. F", round (-3.5); // NB: This one returns-4

// Minimum value
Nslog (@ "res: %. F", fmin (5, 10); // result 5

// Maximum value
Nslog (@ "res: %. F", fmax (5, 10); // result 10

// Absolute value
Nslog (@ "res: %. F", FABS (10); // result 10
Nslog (@ "res: %. F", FABS (-10); // result 10

The trigonometric functions not listed here are also part of the C standard mathematical functions, which can also be viewed in <math. h>.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.