C源码

C源码下载http://mirror.hust.edu.cn/gnu/glibc/
选tar.bz2后缀下载,解压后即可查看源码

mynumber 定义:

/******************************************************************/
/*                                                                */
/* MODULE_NAME:mydefs.h                                           */
/*                                                                */
/* common data and definition                                     */
/******************************************************************/

#ifndef MY_H
#define MY_H

typedef int int4;
typedef union {int4 i[2]; double x;} mynumber;

#define ABS(x)   (((x)>0)?(x):-(x))
#define max(x,y)  (((y)>(x))?(y):(x))
#define min(x,y)  (((y)<(x))?(y):(x))

#endif

log2e three51 hugeint smallint 等均在uexp.h中定义

/******************************************************************/
/*                                                                */
/* MODULE_NAME:uexp.h                                             */
/*                                                                */
/* common data and variables prototype and definition             */
/******************************************************************/

#ifndef UEXP_H
#define UEXP_H

#include "mydefs.h"

const static double one = 1.0, zero = 0.0, hhuge = 1.0e300, tiny = 1.0e-300,
err_0 = 1.000014, err_1 = 0.000016;
const static int4 bigint = 0x40862002,
             badint = 0x40876000,smallint = 0x3C8fffff;
const static int4 hugeint = 0x7FFFFFFF, infint = 0x7ff00000;

#ifdef BIG_ENDI
const static mynumber  inf  = {{0x7FF00000, 0}}; /* inf   */
const static mynumber t256  = {{0x4ff00000, 0}}; /* 2^256 */

const static mynumber ln_two1  = {{0x3FE62E42, 0xFEFA3800}};/*0.69314718055989033 */
const static mynumber ln_two2  = {{0x3D2EF357, 0x93C76730}};/*5.4979230187083712e-14*/
const static mynumber log2e    = {{0x3FF71547, 0x652B82FE}};/* 1.4426950408889634 */

const static mynumber p2       = {{0x3FE00000, 0x000004DC}};/* 0.50000000000013811 */
const static mynumber p3       = {{0x3FC55555, 0x55555A0F}};/* 0.16666666666670024 */

const static mynumber three33  = {{0x42180000, 0}};         /* 25769803776 */
const static mynumber three51  = {{0x43380000, 0}};         /*  6755399441055744 */

#else
#ifdef LITTLE_ENDI
 const static mynumber  inf  = {{0, 0x7FF00000}}; /* inf   */
 const static mynumber t256  = {{0, 0x4ff00000}}; /* 2^256 */

 const static mynumber ln_two1 = {{0xFEFA3800, 0x3FE62E42}};/*0.69314718055989033 */
 const static mynumber ln_two2 = {{0x93C76730, 0x3D2EF357}};/*5.4979230187083712e-14*/
 const static mynumber log2e   = {{0x652B82FE, 0x3FF71547}};/* 1.4426950408889634 */

 const static mynumber p2      = {{0x000004DC, 0x3FE00000}};/* 0.50000000000013811 */
 const static mynumber p3      = {{0x55555A0F, 0x3FC55555}};/* 0.16666666666670024 */

 const static mynumber three33 = {{0, 0x42180000}};   /*  25769803776      */
 const static mynumber three51 = {{0, 0x43380000}};   /*  6755399441055744 */

#endif
#endif
#endif

exp函数定义:e_exp.c

/*
 * IBM Accurate Mathematical Library
 * written by International Business Machines Corp.
 * Copyright (C) 2001 Free Software Foundation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/***************************************************************************/
/*  MODULE_NAME:uexp.c                                                     */
/*                                                                         */
/*  FUNCTION:uexp                                                          */
/*           exp1                                                          */
/*                                                                         */
/* FILES NEEDED:dla.h endian.h mpa.h mydefs.h uexp.h                       */
/*              mpa.c mpexp.x slowexp.c                                    */
/*                                                                         */
/* An ultimate exp routine. Given an IEEE double machine number x          */
/* it computes the correctly rounded (to nearest) value of e^x             */
/* Assumption: Machine arithmetic operations are performed in              */
/* round to nearest mode of IEEE 754 standard.                             */
/*                                                                         */
/***************************************************************************/

#include "endian.h"
#include "uexp.h"
#include "mydefs.h"
#include "MathLib.h"
#include "uexp.tbl"
#include "math_private.h"

double __slowexp(double);

/***************************************************************************/
/* An ultimate exp routine. Given an IEEE double machine number x          */
/* it computes the correctly rounded (to nearest) value of e^x             */
/***************************************************************************/
double __ieee754_exp(double x) {
  double bexp, t, eps, del, base, y, al, bet, res, rem, cor;
  mynumber junk1, junk2, binexp  = {{0,0}};
#if 0
  int4 k;
#endif
  int4 i,j,m,n,ex;

  junk1.x = x;
  m = junk1.i[HIGH_HALF];
  n = m&hugeint;

  if (n > smallint && n < bigint) {

    y = x*log2e.x + three51.x;
    bexp = y - three51.x;      /*  multiply the result by 2**bexp        */

    junk1.x = y;

    eps = bexp*ln_two2.x;      /* x = bexp*ln(2) + t - eps               */
    t = x - bexp*ln_two1.x;

    y = t + three33.x;
    base = y - three33.x;      /* t rounded to a multiple of 2**-18      */
    junk2.x = y;
    del = (t - base) - eps;    /*  x = bexp*ln(2) + base + del           */
    eps = del + del*del*(p3.x*del + p2.x);

    binexp.i[HIGH_HALF] =(junk1.i[LOW_HALF]+1023)<<20;

    i = ((junk2.i[LOW_HALF]>>8)&0xfffffffe)+356;
    j = (junk2.i[LOW_HALF]&511)<<1;

    al = coar.x[i]*fine.x[j];
    bet =(coar.x[i]*fine.x[j+1] + coar.x[i+1]*fine.x[j]) + coar.x[i+1]*fine.x[j+1];

    rem=(bet + bet*eps)+al*eps;
    res = al + rem;
    cor = (al - res) + rem;
    if  (res == (res+cor*err_0)) return res*binexp.x;
    else return __slowexp(x); /*if error is over bound */
  }

  if (n <= smallint) return 1.0;

  if (n >= badint) {
    if (n > infint) return(x+x);               /* x is NaN */
    if (n < infint) return ( (x>0) ? (hhuge*hhuge) : (tiny*tiny) );
    /* x is finite,  cause either overflow or underflow  */
    if (junk1.i[LOW_HALF] != 0)  return (x+x);                /*  x is NaN  */
    return ((x>0)?inf.x:zero );             /* |x| = inf;  return either inf or 0 */
  }

  y = x*log2e.x + three51.x;
  bexp = y - three51.x;
  junk1.x = y;
  eps = bexp*ln_two2.x;
  t = x - bexp*ln_two1.x;
  y = t + three33.x;
  base = y - three33.x;
  junk2.x = y;
  del = (t - base) - eps;
  eps = del + del*del*(p3.x*del + p2.x);
  i = ((junk2.i[LOW_HALF]>>8)&0xfffffffe)+356;
  j = (junk2.i[LOW_HALF]&511)<<1;
  al = coar.x[i]*fine.x[j];
  bet =(coar.x[i]*fine.x[j+1] + coar.x[i+1]*fine.x[j]) + coar.x[i+1]*fine.x[j+1];
  rem=(bet + bet*eps)+al*eps;
  res = al + rem;
  cor = (al - res) + rem;
  if (m>>31) {
    ex=junk1.i[LOW_HALF];
    if (res < 1.0) {res+=res; cor+=cor; ex-=1;}
    if (ex >=-1022) {
      binexp.i[HIGH_HALF] = (1023+ex)<<20;
      if  (res == (res+cor*err_0)) return res*binexp.x;
      else return __slowexp(x); /*if error is over bound */
    }
    ex = -(1022+ex);
    binexp.i[HIGH_HALF] = (1023-ex)<<20;
    res*=binexp.x;
    cor*=binexp.x;
    eps=1.0000000001+err_0*binexp.x;
    t=1.0+res;
    y = ((1.0-t)+res)+cor;
    res=t+y;
    cor = (t-res)+y;
    if (res == (res + eps*cor))
    { binexp.i[HIGH_HALF] = 0x00100000;
      return (res-1.0)*binexp.x;
    }
    else return __slowexp(x); /*   if error is over bound    */
  }
  else {
    binexp.i[HIGH_HALF] =(junk1.i[LOW_HALF]+767)<<20;
    if  (res == (res+cor*err_0)) return res*binexp.x*t256.x;
    else return __slowexp(x);
  }
}

/************************************************************************/
/* Compute e^(x+xx)(Double-Length number) .The routine also receive     */
/* bound of error of previous calculation .If after computing exp       */
/* error bigger than allows routine return non positive number          */
/*else return   e^(x + xx)   (always positive )                         */
/************************************************************************/

double __exp1(double x, double xx, double error) {
  double bexp, t, eps, del, base, y, al, bet, res, rem, cor;
  mynumber junk1, junk2, binexp  = {{0,0}};
#if 0
  int4 k;
#endif
  int4 i,j,m,n,ex;

  junk1.x = x;
  m = junk1.i[HIGH_HALF];
  n = m&hugeint;                 /* no sign */

  if (n > smallint && n < bigint) {
    y = x*log2e.x + three51.x;
    bexp = y - three51.x;      /*  multiply the result by 2**bexp        */

    junk1.x = y;

    eps = bexp*ln_two2.x;      /* x = bexp*ln(2) + t - eps               */
    t = x - bexp*ln_two1.x;

    y = t + three33.x;
    base = y - three33.x;      /* t rounded to a multiple of 2**-18      */
    junk2.x = y;
    del = (t - base) + (xx-eps);    /*  x = bexp*ln(2) + base + del      */
    eps = del + del*del*(p3.x*del + p2.x);

    binexp.i[HIGH_HALF] =(junk1.i[LOW_HALF]+1023)<<20;

    i = ((junk2.i[LOW_HALF]>>8)&0xfffffffe)+356;
    j = (junk2.i[LOW_HALF]&511)<<1;

    al = coar.x[i]*fine.x[j];
    bet =(coar.x[i]*fine.x[j+1] + coar.x[i+1]*fine.x[j]) + coar.x[i+1]*fine.x[j+1];

    rem=(bet + bet*eps)+al*eps;
    res = al + rem;
    cor = (al - res) + rem;
    if  (res == (res+cor*(1.0+error+err_1))) return res*binexp.x;
    else return -10.0;
  }

  if (n <= smallint) return 1.0; /*  if x->0 e^x=1 */

  if (n >= badint) {
    if (n > infint) return(zero/zero);    /* x is NaN,  return invalid */
    if (n < infint) return ( (x>0) ? (hhuge*hhuge) : (tiny*tiny) );
    /* x is finite,  cause either overflow or underflow  */
    if (junk1.i[LOW_HALF] != 0)  return (zero/zero);        /*  x is NaN  */
    return ((x>0)?inf.x:zero );   /* |x| = inf;  return either inf or 0 */
  }

  y = x*log2e.x + three51.x;
  bexp = y - three51.x;
  junk1.x = y;
  eps = bexp*ln_two2.x;
  t = x - bexp*ln_two1.x;
  y = t + three33.x;
  base = y - three33.x;
  junk2.x = y;
  del = (t - base) + (xx-eps);
  eps = del + del*del*(p3.x*del + p2.x);
  i = ((junk2.i[LOW_HALF]>>8)&0xfffffffe)+356;
  j = (junk2.i[LOW_HALF]&511)<<1;
  al = coar.x[i]*fine.x[j];
  bet =(coar.x[i]*fine.x[j+1] + coar.x[i+1]*fine.x[j]) + coar.x[i+1]*fine.x[j+1];
  rem=(bet + bet*eps)+al*eps;
  res = al + rem;
  cor = (al - res) + rem;
  if (m>>31) {
    ex=junk1.i[LOW_HALF];
    if (res < 1.0) {res+=res; cor+=cor; ex-=1;}
    if (ex >=-1022) {
      binexp.i[HIGH_HALF] = (1023+ex)<<20;
      if  (res == (res+cor*(1.0+error+err_1))) return res*binexp.x;
      else return -10.0;
    }
    ex = -(1022+ex);
    binexp.i[HIGH_HALF] = (1023-ex)<<20;
    res*=binexp.x;
    cor*=binexp.x;
    eps=1.00000000001+(error+err_1)*binexp.x;
    t=1.0+res;
    y = ((1.0-t)+res)+cor;
    res=t+y;
    cor = (t-res)+y;
    if (res == (res + eps*cor))
      {binexp.i[HIGH_HALF] = 0x00100000; return (res-1.0)*binexp.x;}
    else return -10.0;
  }
  else {
    binexp.i[HIGH_HALF] =(junk1.i[LOW_HALF]+767)<<20;
    if  (res == (res+cor*(1.0+error+err_1)))
      return res*binexp.x*t256.x;
    else return -10.0;
  }
}

<br> ◎ 文件说明<br> <br> 本文件包括以下内容:<br> <br> ※ 1、文件说明<br> ※ 2、源码操作说明<br> ※ 3、光盘目录清单<br> <br><br> ◎ 源码操作说明<br><br> 源代码使用方法是(以实例1为例):<br> 将该实例的源码,比如实例1的1.c文件(可以在001目录下找到),<br> 拷贝到tc编译器目录下,运行tc.exe,打开编译器,<br> 按【F3】键或者“File->Open”菜单命令,打开1.c文件,<br> 按【Ctrl+F9】键,或者“Run->Run”菜单命令,编译运行该程序。<br> <br><br> ◎ 光盘目录清单如下:<br><br>第一部分 基础篇<br> <br>001 第一个C程序 <br>002 运行多个源文件 <br>003 求整数之积 <br>004 比较实数大小 <br>005 字符的输出 <br>006 显示变量所占字节数 <br>007 自增/自减运算 <br>008 数列求和 <br>009 乘法口诀表 <br>010 猜数字游戏 <br>011 模拟ATM(自动柜员机)界面 <br>012 用一维数组统计学生成绩 <br>013 用二维数组实现矩阵转置 <br>014 求解二维数组的最大/最小元素 <br>015 利用数组求前n个质数 <br>016 编制万年历 <br>017 对数组元素排序 <br>018 任意进制数的转换 <br>019 判断回文数 <br>020 求数组前n元素之和 <br>021 求解钢材切割的最佳订单 <br>022 通过指针比较整数大小 <br>023 指向数组的指针 <br>024 寻找指定元素的指针 <br>025 寻找相同元素的指针 <br>026 阿拉伯数字转换为罗马数字 <br>027 字符替换 <br>028 从键盘读入实数 <br>029 字符行排版 <br>030 字符排列 <br>031 判断字符串是否回文 <br>032 通讯录的输入输出 <br>033 扑克牌的结构表示<br>034 用“结构”统计学生成绩 <br>035 报数游戏 <br>036 模拟社会关系 <br>037 统计文件的字符数 <br>038 同时显示两个文件的内容 <br>039 简单的文本编辑器 <br>040 文件的字数统计程序 <br>041 学生成绩管理程序 <br> <br>第二部分 数据结构篇<br> <br>042 插入排序 <br>043 希尔排序 <br>044 冒泡排序 <br>045 快速排序 <br>046 选择排序 <br>047 堆排序 <br>048 归并排序 <br>049 基数排序 <br>050 二叉搜索树操作 <br>051 二项式系数递归 <br>052 背包问题 <br>053 顺序表插入和删除 <br>054 链表操作(1) <br>055 链表操作(2) <br>056 单链表就地逆置 <br>057 运动会分数统计 <br>058 双链表 <br>059 约瑟夫环 <br>060 记录个人资料 <br>061 二叉树遍利 <br>062 浮点数转换为字符串 <br>063 汉诺塔问题 <br>064 哈夫曼编码 <br>065 图的深度优先遍利 <br>066 图的广度优先遍利<br>067 求解最优交通路径 <br>068 八皇后问题<br>069 骑士巡游 <br>070 用栈设置密码 <br>071 魔王语言翻译 <br>072 火车车厢重排 <br>073 队列实例 <br>074 K阶斐波那契序列 <br> <br>第三部分 数值计算与趣味数学篇<br> <br>075 绘制余弦曲线和直线的迭加<br>076 计算高次方数的尾数 <br>077 打鱼还是晒网 <br>078 怎样存钱以获取最大利息 <br>079 阿姆斯特朗数 <br>080 亲密数 <br>081 自守数 <br>082 具有abcd=(ab+cd)2性质的数 <br>083 验证歌德巴赫猜想<br>084 素数幻方 <br>085 百钱百鸡问题 <br>086 爱因斯坦的数学题 <br>087 三色球问题<br>088 马克思手稿中的数学题 <br>089 配对新郎和新娘 <br>090 约瑟夫问题<br>091 邮票组合 <br>092 分糖果 <br>093 波瓦松的分酒趣题 <br>094 求π的近似值 <br>095 奇数平方的有趣性质<br>096 角谷猜想 <br>097 四方定理 <br>098 卡布列克常数 <br>099 尼科彻斯定理 <br>100 扑克牌自动发牌 <br>101 常胜将军 <br>102 搬山游戏<br>103 兔子产子(菲波那契数列) <br>104 数字移动 <br>105 多项式乘法 <br>106 产生随机数 <br>107 堆栈四则运算 <br>108 递归整数四则运算 <br>109 复平面作图 <br>110 绘制彩色抛物线 <br>111 绘制正态分布曲线 <br>112 求解非线性方程 <br>113 实矩阵乘法运算<br>114 求解线性方程 <br>115 n阶方阵求逆 <br>116 复矩阵乘法 <br>117 求定积分 <br>118 求满足特异条件的数列 <br>119 超长正整数的加法 <br> <br>第四部分 图形篇<br> <br>120 绘制直线 <br>121 绘制圆 <br>122 绘制圆弧 <br>123 绘制椭圆<br>124 设置背景色和前景色<br>125 设置线条类型 <br>126 设置填充类型和填充颜色 <br>127 图形文本的输出 <br>128 金刚石图案<br>129 飘带图案 <br>130 圆环图案 <br>131 肾形图案 <br>132 心脏形图案 <br>133 渔网图案 <br>134 沙丘图案<br>135 设置图形方式下的文本类型 <br>136 绘制正多边形 <br>137 正六边形螺旋图案 <br>138 正方形螺旋拼块图案<br>139 图形法绘制圆 <br>140 递归法绘制三角形图案 <br>141 图形法绘制椭圆 <br>142 抛物样条曲线 <br>143 Mandelbrot分形图案<br>144 绘制布朗运动曲线 <br>145 艺术清屏 <br>146 矩形区域的颜色填充 <br>147 VGA256色模式编程 <br>148 绘制蓝天图案 <br>149 屏幕检测程序 <br>150 运动的小车动画 <br>151 动态显示位图 <br>152 利用图形页实现动画<br>153 图形时钟 <br>154 音乐动画 <br> <br>第五部分 系统篇<br> <br>155 读取DOS系统中的国家信息 <br>156 修改环境变量 <br>157 显示系统文件表 <br>158 显示目录内容 <br>159 读取磁盘文件 <br>160 删除目录树 <br>161 定义文本模式 <br>162 设计立体窗口 <br>163 彩色弹出菜单 <br>164 读取CMOS信息 <br>165 获取BIOS设备列表 <br>166 锁住硬盘 <br>167 备份/恢复硬盘分区表 <br>168 设计口令程序 <br>169 程序自我保护<br> <br>第六部分 常见试题解答篇<br> <br>170 水果拼盘 <br>171 小孩吃梨 <br>172 删除字符串中的特定字符 <br>173 求解符号方程 <br>174 计算标准差 <br>175 求取符合特定要求的素数 <br>176 统计符合特定条件的数 <br>177 字符串倒置 <br>178 部分排序 <br>179 产品销售记录处理 <br>180 特定要求的字符编码 <br>181 求解三角方程 <br>182 新完全平方数 <br>183 三重回文数 <br>184 奇数方差 <br>185 统计选票 <br>186 同时整除 <br>187 字符左右排序 <br>188 符号算式求解 <br>189 数字移位 <br>190 统计最高成绩 <br>191 比较字符串长度 <br>192 合并整数 <br>193 矩阵逆置<br>194 删除指定的字符<br>195 括号匹配 <br>196 字符串逆置 <br>197 SIX/NINE问题 <br>198 单词个数统计 <br>199 方差运算 <br>200 级数运算 <br>201 输出素数 <br>202 素数题 <br>203 序列排序 <br>204 整数各位数字排序 <br>205 字符串字母移位 <br>206 Fibonacc数列 <br> <br>第七部分 游戏篇<br> <br>207 商人过河游戏 <br>208 吃数游戏 <br>209 解救人质游戏 <br>210 打字训练游戏 <br>211 双人竞走游戏 <br>212 迷宫探险游戏 <br>213 迷你撞球游戏<br>214 模拟扫雷游戏 <br>215 推箱子游戏 <br>216 五子棋游戏 <br> <br>第八部分 综合实例篇<br> <br>217 综合CAD系统 <br>218 功能强大的文本编辑器<br>219 图书管理系统<br>220 进销存管理系统
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值