logo资料库

C++数学函数库.doc

第1页 / 共31页
第2页 / 共31页
第3页 / 共31页
第4页 / 共31页
第5页 / 共31页
第6页 / 共31页
第7页 / 共31页
第8页 / 共31页
资料共31页,剩余部分请下载后查看
C/C++头文件一览
C++中数学函数
函数
C++新手必问之头文件
C/C++头文件一览 传统 C/C++ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //设定插入点 //字符处理 //定义错误码 //浮点数处理 //文件输入/输出 //参数化输入/输出 //数据流输入/输出 //定义各种数据类型最值常量 //定义本地化函数 //定义数学函数 //定义输入/输出函数 //定义杂项函数及内存分配函数 //字符串处理 //基于数组的输入/输出 //定义关于时间的函数 //宽字符处理及输入/输出 //宽字符分类 ////////////////////////////////////////////////////////////////////////// 标准 C++ (同上的不再注释) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //STL 通用算法 //STL 位集容器 //字符处理 //定义错误码 //定义本地化函数 //定义数学函数 //复数类 //定义输入/输出函数 //定义杂项函数及内存分配函数 //字符串处理 //定义关于时间的函数 //STL 双端队列容器 //异常处理类 //文件输入/输出 //STL 定义运算函数(代替运算符) //定义各种数据类型最值常量
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //STL 线性列表容器 //STL 映射容器 //参数化输入/输出 //基本输入/输出支持 //输入/输出系统使用的前置声明 //数据流输入/输出 //基本输入流 //基本输出流 //STL 队列容器 //STL 集合容器 //基于字符串的流 //STL 堆栈容器 //标准异常类 //底层输入/输出支持 //字符串类 //STL 通用模板类 //STL 动态数组容器 //宽字符处理及输入/输出 //宽字符分类 ////////////////////////////////////////////////////////////////////////// C99 增加 #include #include #include #include #include #include //复数处理 //浮点环境 //整数格式转换 //布尔环境 //整型环境 //通用类型数学宏 不同的编译器还会提供特有的头文件,但是没有通用性。如 graphics.h 和 bios.h 是 TC 自 带的,在别的编译器上就不能用它。另外我们还可以在程序里定义自己的头文件。 C++中数学函数 int abs(int i) 返回整型参数 i 的绝对值 double cabs(struct complex znum) 返回复数 znum 的绝对值 double fabs(double x) 返回双精度参数 x 的绝对值
long labs(long n) 返回长整型参数 n 的绝对值 double exp(double x) 返回指数函数 ex 的值 double frexp(double value,int *eptr) 返回 value=x*2n 中 x 的值,n 存贮在 eptr 中 double ldexp(double value,int exp); 返回 value*2exp 的值 double log(double x) 返回 logex 的值 double log10(double x) 返回 log10x 的值 double pow(double x,double y) 返回 xy 的值 double pow10(int p) 返回10p 的值 double sqrt(double x) 返回+√x 的值 double acos(double x) 返回 x 的反余弦 cos-1(x)值,x 为弧度 double asin(double x) 返回 x 的反正弦 sin-1(x)值,x 为弧度 double atan(double x) 返回 x 的反正切 tan-1(x)值,x 为弧度 double atan2(double y,double x) 返回 y/x 的反正切 tan-1(x)值,y 的 x 为弧 度 double cos(double x) 返回 x 的余弦 cos(x)值,x 为弧度 double sin(double x) 返回 x 的正弦 sin(x)值,x 为弧度 double tan(double x) 返回 x 的正切 tan(x)值,x 为弧度 double cosh(double x) 返回 x 的双曲余弦 cosh(x)值,x 为弧度 double sinh(double x) 返回 x 的双曲正弦 sinh(x)值,x 为弧度 double tanh(double x) 返回 x 的双曲正切 tanh(x)值,x 为弧度 double hypot(double x,double y) 返回直角三角形斜边的长度(z), x 和 y 为直角边的长度,z2=x2+y2 double ceil(double x) 返回不小于 x 的最小整数 double floor(double x) 返回不大于 x 的最大整数 void srand(unsigned seed) 初始化随机数发生器 int rand() 产生一个随机数并返回这个数 double poly(double x,int n,double c[])从参数产生一个多项式 double modf(double value,double *iptr)将双精度数 value 分解成尾数和阶 double fmod(double x,double y) 返回 x/y 的余数 double frexp(double value,int *eptr) 将双精度数 value 分成尾数和阶 double atof(char *nptr) 将字符串 nptr 转换成浮点数并返回这个浮点数 double atoi(char *nptr) 将字符串 nptr 转换成整数并返回这个整数 double atol(char *nptr) 将字符串 nptr 转换成长整数并返回这个整数 char *ecvt(double value,int ndigit,int *decpt,int *sign) 将浮点数 value 转换成字符串并返回该字符串 char *fcvt(double value,int ndigit,int *decpt,int *sign) 将浮点数 value 转换成字符串并返回该字符串 char *gcvt(double value,int ndigit,char *buf) 将数 value 转换成字符串并存于 buf 中,并返回 buf 的指针 char *ultoa(unsigned long value,char *string,int radix) 将无符号整型数 value 转换成字符串并返回该字符串,radix 为转换时所用基数
char *ltoa(long value,char *string,int radix) 将长整型数 value 转换成字符串并返回该字符串,radix 为转换时所用基数 char *itoa(int value,char *string,int radix) 将整数 value 转换成字符串存入 string,radix 为转换时所用基数 double atof(char *nptr) 将字符串 nptr 转换成双精度数,并返回这个数,错误 返回0 int atoi(char *nptr) 将字符串 nptr 转换成整型数, 并返回这个数,错误返回0 long atol(char *nptr) 将字符串 nptr 转换成长整型数,并返回这个数,错误返 回0 double strtod(char *str,char **endptr)将字符串 str 转换成双精度数,并返 回这个数, long strtol(char *str,char **endptr,int base)将字符串 str 转换成长整型 数, 并返回这个数, int matherr(struct exception *e) 用户修改数学错误返回信息函数(没有必要使用) double _matherr(_mexcep why,char *fun,double *arg1p, double *arg2p,double retval) 用户修改数学错误返回信息函数(没有必要使用) unsigned int _clear87() 清除浮点状态字并返回原来的浮点状态 void _fpreset() 重新初使化浮点数学程序包 unsigned int _status87() 返回浮点状态字 目录函数,所在函数库为 dir.h、dos.h int chdir(char *path) 使指定的目录 path(如:"C:\\WPS")变成当前的工作 目录,成 功返回0 int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的 文件,成功 返回0 pathname 为指定的目录名和文件名,如"C:\\WPS\\TXT" ffblk 为指定的保存文件信息的一个结构,定义如下: ┏━━━━━━━━━━━━━━━━━━┓ ┃struct ffblk┃ ┃{ ┃ ┃ char ff_reserved[21]; /*DOS 保留字*/┃ ┃ char ff_attrib; /*文件属性*/ ┃ ┃ int ff_ftime; /*文件时间*/ ┃ ┃ int ff_fdate; /*文件日期*/ ┃ ┃ long ff_fsize; /*文件长度*/ ┃ ┃ char ff_name[13]; /*文件名*/ ┃ ┃} ┃
┗━━━━━━━━━━━━━━━━━━┛ attrib 为文件属性,由以下字符代表 ┏━━━━━━━━━┳━━━━━━━━┓ ┃FA_RDONLY 只读文件┃FA_LABEL 卷标号┃ ┃FA_HIDDEN 隐藏文件┃FA_DIREC 目录 ┃ ┃FA_SYSTEM 系统文件┃FA_ARCH 档案 ┃ ┗━━━━━━━━━┻━━━━━━━━┛ 例: struct ffblk ff; findfirst("*.wps",&ff,FA_RDONLY); int findnext(struct ffblk *ffblk) 取匹配 finddirst 的文件,成功返回0 void fumerge(char *path,char *drive,char *dir,char *name,char *ext) 此函数通过盘符 drive(C:、A:等),路径 dir(\TC、\BC\LIB 等), 文件名 name(TC、WPS 等),扩展名 ext(.EXE、.COM 等)组成一个文件名 存与 path 中. int fnsplit(char *path,char *drive,char *dir,char *name,char *ext) 此函数将文件名 path 分解成盘符 drive(C:、A:等),路径 dir(\TC、\BC\LIB 等), 文件名 name(TC、WPS 等),扩展名 ext(.EXE、.COM 等),并分别存入相应的变量中. int getcurdir(int drive,char *direc) 此函数返回指定驱动器的当前工作目 录名称 drive 指定的驱动器(0=当前,1=A,2=B,3=C 等) direc 保存指定驱动器当前工作路径的变量 成功返回0 char *getcwd(char *buf,iint n) 此函数取当前工作目录并存入 buf 中,直到 n 个字 节长为为止.错误返回 NULL int getdisk() 取当前正在使用的驱动器,返回一个整数(0=A,1=B,2=C 等) int setdisk(int drive) 设置要使用的驱动器 drive(0=A,1=B,2=C 等), 返回可使用驱动器总数 int mkdir(char *pathname) 建立一个新的目录 pathname,成功返回0 int rmdir(char *pathname) 删除一个目录 pathname,成功返回0 char *mktemp(char *template) 构 造一 个当 前目 录上 没有 的文 件 名并 存 于 template 中 char *searchpath(char *pathname) 利用 MSDOS 找出文件 filename 所在路径, ,此函数使用 DOS 的 PATH 变量,未找到文件返回 NULL 进程函数,所在函数库为 stdlib.h、process.h void abort() 此 函 数 通 过 调 用 具 有 出 口 代 码 3 的 _exit 写 一 个 终 止 信 息 于 stderr, 并异常终止程序。无返回值 int exec…装入和运行其它程序 int execl( char *pathname,char *arg0,char *arg1,…,char *argn,NULL) int execle( char *pathname,char *arg0,char *arg1,…,
char *argn,NULL,char *envp[]) int execlp( char *pathname,char *arg0,char *arg1,…,NULL) int execlpe(char *pathname,char *arg0,char *arg1,…,NULL,char *envp[]) int execv( char *pathname,char *argv[]) int execve( char *pathname,char *argv[],char *envp[]) int execvp( char *pathname,char *argv[]) int execvpe(char *pathname,char *argv[],char *envp[]) exec 函数族装入并运行程序 pathname,并将参数 arg0(arg1,arg2,argv[],envp[])传递给子程序,出错返回-1 在 exec 函数族中,后缀 l、v、p、e 添加到 exec 后, 所指定的函数将具有某种操作能力 有后缀 p 时,函数可以利用 DOS 的 PATH 变量查找子程序文件。 l 时,函数中被传递的参数个数固定。 v 时,函数中被传递的参数个数不固定。 e 时,函数传递指定参数 envp,允许改变子进程的环境, 无后缀 e 时,子进程使用当前程序的环境。 void _exit(int status)终止当前程序,但不清理现场 void exit(int status) 终止当前程序,关闭所有文件,写缓冲区的输出(等待输 出), 并调用任何寄存器的"出口函数",无返回值 int spawn…运行子程序 int spawnl( int mode,char *pathname,char *arg0,char *arg1,…, char *argn,NULL) int spawnle( int mode,char *pathname,char *arg0,char *arg1,…, char *argn,NULL,char *envp[]) int spawnlp( int mode,char *pathname,char *arg0,char *arg1,…, char *argn,NULL) int spawnlpe(int mode,char *pathname,char *arg0,char *arg1,…, char *argn,NULL,char *envp[]) int spawnv( int mode,char *pathname,char *argv[]) int spawnve( int mode,char *pathname,char *argv[],char *envp[]) int spawnvp( int mode,char *pathname,char *argv[]) int spawnvpe(int mode,char *pathname,char *argv[],char *envp[]) spawn 函数族在 mode 模式下运行子程序 pathname,并将参数 arg0(arg1,arg2,argv[],envp[])传递给子程序.出错返回-1 mode 为运行模式 mode 为 P_WAIT 表示在子程序运行完后返回本程序 P_NOWAIT 表示在子程序运行时同时运行本程序(不可用) P_OVERLAY 表示在本程序退出后运行子程序 在 spawn 函数族中,后缀 l、v、p、e 添加到 spawn 后, 所指定的函数将具有某种操作能力 有后缀 p 时, 函数利用 DOS 的 PATH 查找子程序文件
l 时, 函数传递的参数个数固定. v 时, 函数传递的参数个数不固定. e 时, 指定参数 envp 可以传递给子程序,允许改变子程序运行环境. 当无后缀 e 时,子程序使用本程序的环境. int system(char *command) 将 MSDOS 命令 command 传递给 DOS 执行 转换子程序,函数库为 math.h、stdlib.h、ctype.h、float.h char *ecvt(double value,int ndigit,int *decpt,int *sign) 将浮点数 value 转换成字符串并返回该字符串 char *fcvt(double value,int ndigit,int *decpt,int *sign) 将浮点数 value 转换成字符串并返回该字符串 char *gcvt(double value,int ndigit,char *buf) 将数 value 转换成字符串并存于 buf 中,并返回 buf 的指针 char *ultoa(unsigned long value,char *string,int radix) 将无符号整型数 value 转换成字符串并返回该字符串,radix 为转换时所用基数 char *ltoa(long value,char *string,int radix) 将长整型数 value 转换成字符串并返回该字符串,radix 为转换时所用基数 char *itoa(int value,char *string,int radix) 将整数 value 转换成字符串存入 string,radix 为转换时所用基数 double atof(char *nptr) 将字符串 nptr 转换成双精度数,并返回这个数,错误 返回0 int atoi(char *nptr) 将字符串 nptr 转换成整型数, 并返回这个数,错误返回0 long atol(char *nptr) 将字符串 nptr 转换成长整型数,并返回这个数,错误返 回0 double strtod(char *str,char **endptr)将字符串 str 转换成双精度数,并返 回这个数, long strtol(char *str,char **endptr,int base)将字符串 str 转换成长整型 数, 并返回这个数, int toascii(int c) 返回 c 相应的 ASCII int tolower(int ch) 若 ch 是大写字母('A'-'Z')返回相应的 小写字母('a'-'z') int _tolower(int ch) 返回 ch 相应的小写字母('a'-'z') int toupper(int ch) 若 ch 是小写字母('a'-'z')返回相应的 大写字母('A'-'Z') int _toupper(int ch) 返回 ch 相应的大写字母('A'-'Z') 诊断函数,所在函数库为 assert.h、math.h void assert(int test) 一个扩展成 if 语句那样的宏,如果 test 测试失败, 就显示一个信息并异常终止程序,无返回值 void perror(char *string) 本函数将显示最近一次的错误信息,格式如下: 字符串 string:错误信息
char *strerror(char *str) 本函数返回最近一次的错误信息,格式如下: 字符串 str:错误信息 int matherr(struct exception *e) 用户修改数学错误返回信息函数(没有必要使用) double _matherr(_mexcep why,char *fun,double *arg1p, double *arg2p,double retval) 用户修改数学错误返回信息函数(没有必要使用) 输入输出子程序,函数库为 io.h、conio.h、stat.h、dos.h、stdio.h、signal.h int kbhit() 本函数返回最近所敲的按键 int fgetchar() 从控制台(键盘)读一个字符,显示在屏幕上 int getch() 从控制台(键盘)读一个字符,不显示在屏幕上 int putch() 向控制台(键盘)写一个字符 int getchar() 从控制台(键盘)读一个字符,显示在屏幕上 int putchar() 向控制台(键盘)写一个字符 int getche() 从控制台(键盘)读一个字符,显示在屏幕上 int ungetch(int c) 把字符 c 退回给控制台(键盘) char *cgets(char *string) 从控制台(键盘)读入字符串存于 string 中 int scanf(char *format[,argument…])从控制台读入一个字符串,分别对各个 参数进行 赋值,使用 BIOS 进行输出 int vscanf(char *format,Valist param)从控制台读入一个字符串,分别对各个 参数进行 赋值,使用 BIOS 进行输出,参数从 Valist param 中取得 int cscanf(char *format[,argument…])从控制台读入一个字符串,分别对各个 参数进行 赋值,直接对控制台作操作,比如显示器在显示时字符时即为直接写频方式显示 int sscanf(char *string,char *format[,argument,…])通过字符串 string, 分别对各个 参数进行赋值 int vsscanf(char *string,char *format,Vlist param)通过字符串 string,分 别对各个 参数进行赋值,参数从 Vlist param 中取得 int puts(char *string) 发关一个字符串 string 给控制台(显示器), 使用 BIOS 进行输出 void cputs(char *string) 发送一个字符串 string 给控制台(显示器), 直接对控制台作操作,比如显示器即为直接写频方式显示 int printf(char *format[,argument,…]) 发送格式化字符串输出给控制台(显 示器) 使用 BIOS 进行输出 int vprintf(char *format,Valist param) 发送格式化字符串输出给控制台(显 示器)
分享到:
收藏