C Language standard library (understanding) __c language

Source: Internet
Author: User
Tags assert in degrees pow random seed

[+]

Overview

The C language function manual is also known as the C standard library. The C standard library consists of functions, type definitions, and macros declared in 15 header files, each representing a range of programming capabilities. It is said that the C standard library can be divided into 3 groups, how to correctly and skillfully use them, you can be able to distinguish the corresponding 3 level of programmers:

Qualified programmers:<stdio.h>, <ctype.h>, <stdlib.h>, <string.h>

Skilled programmer:<assert.h>, <limits.h>, <stddef.h>, <time.h>

Excellent programmers:<float.h>, <math.h>, <error.h>, <locale.h>, <setjmp.h>, <signal.h>, < Stdarg.h> Introduction to the mathematical calculation formula in a,<math.h> 1. Trigonometric function
Double sin (double); sine
Double cos (double); cosine
Double tan (double); tangent
2, Inverse trigonometric functions
Double asin (double); Results between [-PI/2, PI/2]
Double ACOs (double); Results between [0, PI]
Double Atan (double); Tangent (primary value), the result is between [-PI/2, PI/2]
Double atan2 (double, double); Tangent (integer circle value), resulting in [-pi, PI] (y/x tangent value)
3. Double Curved Trigonometric Functions
Double Sinh (double);
Double cosh (double);
Double Tanh (double);
4. Index and logarithm
Double exp (double), the power of the natural number E (The x-th square value at the end of the E) is obtained
Double sqrt (double) open square
Double log (double); Logarithm with e as the base
Double log10 (double); 10-based logarithm
Double pow (double x, double y); Calculate y-Power with X as base
float POWF (float x, float y); function is consistent with POW, except that both input and output are floating-point numbers
Double Pow10 (double x, double y); 10 x-Square (Power)
5. Take the whole
Double ceil (double); Take the whole (that is, the smallest integer that is not less than a number)
Double floor (double); Remove the whole (that is, the largest integer that is not greater than a number)
6. Absolute value
Double fabs (double);
Double cabs (struct complex znum); To find the absolute value of plural
int abs (int); To find the absolute value of an integer
Long Labs (long); Take long integer absolute value 7, standardize floating-point number
Double Frexp (double f, int *p); Standard floating-point number, F = x * 2^p, known F for X, p (x between [0.5, 1])
Double Ldexp (double x, int p); In contrast to Frexp, known as x, P F
7. Take the whole and take the remainder
Double Modf (double, double*); Returns the integer part of the parameter by the pointer, returning the decimal part
Double Fmod (double, double); Returns the remainder of the division between two parameters (modulo on floating-point numbers)
8. Other
Double Hypot (double x, double y); known right triangle two right-angled edge length, bevel length
Double Ldexp (double x, int exponent); compute x* (exponent power of 2)
Double poly (double x, int degree, double coeffs []), calculating polynomial
Double round (double); Rounded rounding
Double Fmax (double, double);
Double min (double,double), minimum value
int rand (void); Find random numbers

Precautions:
There is no ready-made cot trigonometric functions, you can use Tan (pi/2-x) to achieve
It is emphasized that the 1-3-class arguments are for values that are expressed in radians, not in degrees.
For the general logarithmic solution, consider using the mathematical logarithmic transformation to achieve.
About Fmod: Taking into account that% only applies to integer data, here is a function specifically for the remainder operations of real data.
int rand (void) When you use this function, remember to give the random seed oh, or not the real random number. A random seed can be produced with srand ((unsigned int) time (NULL));
two,<assert.h> function

The header file of the Assert.h C standard library provides a macro called an assertion that can be used to validate a program, if the assumption is wrong, and prints a diagnostic message.

The following are the only function definitions in the header assert.h:

void assert (int expression)

This is actually a macro, not a function that can be used to add diagnostics in the C program. Expression is equivalent to an if expression inside

Example: [OBJC] View plain copy-(void) viewdidload {[Super viewdidload];      int i = 1;      ASSERT (I>1); NSLog (@ "Print out the value of I is:%d", i);

Print Result: [OBJC] view Plain copy assertion failed: (i>1), function-[viewcontroller Viewdidload], file/users/ ADMIN/DESKTOP/XCODECODE/MATH.H/MATH.H/VIEWCONTROLLER.M, line 20.

Note :

* Assert is a macro that works only in the debug version and is not useful in release versions. ()

* When assert diagnostics fail, assert prints the message to stderr. As you can see in Figure 1, the Assert diagnostic information is expressed as: Assertion failed: expression (expression), filename (file name) for program (file) error, line nnn. Asset then invokes the execution of the abort interrupt function, which is defined in the preprocessing macros (preprocessor macros) __file__ and __line__ by the source file name (the origin filename) and line number.

* After debugging, you can disable the assert call by inserting #define NDEBUG before the statement containing #include <assert.h>.

The sample code is as follows:
[OBJC] view plain copy <span style= "FONT-SIZE:12PX;" > #include <stdio.h> #define NDEBUG #include <assert.h></span>

      *nsassert is also a macro inside objective-c, and he does almost as much as assert () and does nothing in release mode, and Debug asserts. (in release mode Xcode defines a macro ns_block_assertions, which is similar to the ndebug in C)
      Nsassert (CONDITION,DESC), Translated in debug mode to
[OBJC]   View plain  copy   <span style= "FONT-SIZE:12PX;" >      if  (!) ( condition))  {             [[nsassertionhandler  currenthandler] handlefailurei

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.