Search This Blog

Monday, November 30, 2009

iPhone VolumeSettingsAlertShow




MPVolumeSettingsAlertShow();

Wednesday, November 25, 2009

converts a string of hexadecimal digits into its equivalent integer value


#import
#define key 16

void tran (char s[]) {
int i = 0;
int sum = 0;
while (i if (s[i]>='0'&&s[i]<='9') {
sum += (s[i]-'0')*pow(key,strlen(s)-1-i);
}else if (s[i]>='A'&&s[i]<='F'){
sum += (s[i]-'A'+10)*pow(key, strlen(s)-1-i);
}else if (s[i]>='a'&&s[i]<='f') {
sum += (s[i]-'a'+10)*pow(key, strlen(s)-1-i);
}
i++;
}
printf("%s等于%d\n",s,sum);
}

//去掉回车
/***********************> ReplaceReturnAtEndOfString <*/
void ReplaceReturnAtEndOfString( char *theString ) {
int length = strlen( theString );

theString[ length - 1 ] = '\0';
}

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
char s[20];
loop: printf("16进制转10进制");
fgets(s, 20, stdin );
ReplaceReturnAtEndOfString(s);
tran(s);
goto loop;
[pool drain];
return 0;
}

Sunday, November 22, 2009

Bullet 3D 物理引擎 简析(2)


1. 理论准备:本科的数学分析,理论力学,线性代数。 尤其是理论力学中的朗格朗日动力学部分
最好能回忆起来。 碰撞检测上面列的两本书的内容就足够了,如果进一步挖掘需要看
计算几何方面的书
2. 补一个架构图 引自[1]的12页,其中的STC即为上次分析中的islandmanager



碰撞响应的分析

1. 约束分类:可积约束,不可积约束 ,摩擦力(见[1]第四章)
2. 整个bullet在动力学方面的核心就是btSequentialImpulseConstraintSolver 这个类及其实现
这个类名字可以翻译为基于顺序冲量处理方法的约束求解过程(这是个缩略的函数名不可直译)。
这个名字的含义很重要,表示了这个求解方法是按照顺序来处理约束以及接触点,摩擦力,one by one
并且求解的结果是冲量的范数。整个的原理部分可以参照[1]的第4章节,[2]的第7章。
3. btSequentialImpulseConstraintSolver 的全部重心在于solveGroupCacheFriendlySetup
负责对于三种约束进行计算准备(包括计算一些解方程要用到的常量以及中间变量等)和 solveGroupCacheFriendlyIterations
负责应用PGS[9]求解。



solveGroupCacheFriendlySetup 分析

1. 首先是关于可积约束的计算准备:首先是遍历约束数组,每一个约束都需要计算自己的jacbian(关键概念参照[1]的第四章)
初始化一些常量和中间变量 这里有些概念和公式比如惯性张量等都可以在[1],[8]中找到
2. 关于接触点约束的计算准备:这里有个重要的函数convertContact, 把从碰撞检测阶段获得的接触点转化为不可积约束并初始化常量和中间变量,
以及初始化摩擦力的相关数据,摩擦力计算参照[1]第4章第6节 其中引用的公式也来自[1] 但是考虑到实时性,并不完全一致。



solveGroupCacheFriendlyIterations 分析

* 分别根据[9]中的PGS算法求解3类约束,重点是基于SIMD的优化,以及递归次数10的设置。
对于PGS的理解最好从Gauss-Sidel数值解法入手。
对于各类约束类型对应的jacbian 参照[1]第四章节71页
* 核心的数据结构
btSolverConstraint 存储每个约束的计算常量中间变量
btSolverBody 几何刚体对象和动力学求解对象的连接体
* 其它
整个过程中涉及到了穿透矫正[1]111页,时间递进[1]90页,bullet 没有采用多接触点同时求解的方法,会带来一些误差


[1]的第4章是整个动力学模拟的灵魂,理解了这章,整个求解过程都容易理解

下一步计划写softbody的分析

参考书目
[1]Stable, Robust, and Versatile Multibody Dynamics Animation
Kenny Erleben
关于多刚体-动力学模拟必读的文章 bullet很多实现都参考了此文
很好的一篇综述论文,实际上是下面这本书的草稿
网上可以下到免费的pdf版本

[2]physics based animation
Kenny Erleben
同作者的一本全面且用较为严格的数学语言描述物理模拟的经典好书
涵盖刚体,流体,非刚体
国内尚未引进,目前暂无电子版。 适合深度挖掘者使用。

[3]Game Physics, David H. Eberly
从游戏开发角度来阐释物理模拟,比较实用,内容稍显陈旧。 有电子版,不好找

[4]Physics.Engine.Development
同样是阐述物理模拟,不过是为入门读者准备,比较浅显易懂。 有电子版

[5]Collision Detection in Interactive 3D Environments
对照作者自己实现的solid碰撞检测引擎来讲述,很好的一本书。又电子版

[6]Real-Time Collision Detection
比较全面的阐述了碰撞检测,是一个初步入门的好书, 有电子版
[7]Computational Geometry in C
如果想在几何结构方面进一步挖掘,这本书不错,清华翻译的二版有卖,翻译的也好
三版已出,似乎还没引进

[8]Classical Mechanics. Prentice Hall, 3rd edition, January 2002.
理论力学,很多东西忘记了可以查看这本书 有电子版

[9]Iterative Dynamics with Temporal Coherence
一篇在GDC2005?上的ppt,简短描述有关PGS算法的问题,是Box2D的作者

Bullet 3D 物理引擎 简析(1)

原创帖子, 转载请注明出处,作者信息.
这个是自己分析bullet的代码过程中的笔记,比较简陋, 希望抛砖引玉, 欢迎板砖

作者: 马良 (www.iphonephysics.com) (此blog需Over GW)
0 前提假设
计算机图形学中的物理模拟实际上只是追求视觉近似,而并非精确的物理模拟
同时物理引擎从简化计算考虑, 不与渲染引擎共享对象数据采用独立的一套数据.

1 架构分析
物理模拟的基础是建立在一些核心几何结构之上.
核心的几何概念有

1. 形状 (shape) : shape 抽象出了几何形状的特征, 比如长方体, 球, 四面体,凸包. bullet中的形状类型非常丰富有几十种之多. 由于几何形状的特征是和具体对象无关的,所以一种形状只要维持一个实例即可, 所有映射到该shape的对象可以共享这个实例.
2. 包围体层次(BVH) 这个的概念可以在书中查找,一般有AABB, OBB, K-Dop, Convex Hull. Bullet 中采用的是AABB
3. 空间划分数据机构节点 bullet 采用AABB
4. 空间划分数据结构(通常是树) Bullet 中采用的主要是Dynamic AABB Tree (刚体 , 值得注意的是这里用得是曼哈顿距离) 和 Sweep and Prune (soft body)
5. 碰撞检测算法(这里也有很多选择完全根据检测对象来定,GJK ,sweep prune 是复杂的, box2box, shpere2shpere .... 比较简单.
6. 接触点(contract point, manifold)
7. 约束类型(bullet 提供了6种,见bullet 手册)
8. motion state 是对渲染引擎提供的一个接口, 便于渲染引擎更新渲染对象的位置


完成几何基础构建后在一个场景(collision world)内 加入 各个被模拟的物理对象(collision object)每个物理对象被映射到对映的shape, 空间划分数据结构节点. 如果再在这些对象身上附加例如速度,角速度,转动惯量等物理特征,就演化为rigid object. Soft body 情况复杂一些, 一般由mesh构成 尚在分析中.

物理模拟过程分为2个主要阶段.

* Broad Phase: 首先进行远距碰撞检测, 利用空间分割结构,如果不在同一个子树内的物体不可能相交不用去计算, 在同一个子树内的物体被放入 overlapping pair, 再进一步由对应的算法来计算出接触点等信息. 采用哪一种算法取决于算法配置矩阵(见bullet 手册)
* Narrow Phase: 根据overlapping pairs 的分布情况计算出碰撞对象岛(collision Island).而后依次对各个岛进行约束分析. 亦即碰撞响应. Bullet 采用的是Sequential Impulse ConstraintSolver(http://www.gphysics.com/archives/28) 约束分析是一个非常复杂的话题,涉及到PGS算法的简化,后文会有介绍. 约束分析会根据所设定的约束类型来计算碰撞后各个对象所对应的位置,速度等, 然后与渲染引擎同步motion state.

Tuesday, November 17, 2009

C language (Write an alternative version of squeeze(s1,s2) that deletes each character in s1 that matches any character in the string s2)

char is Int


#import
#include
#include
#define N 40

void fun(char s[],int c)
{
int i=0;
char*p;
p=s;
while(*p)
{
if(*p!=c)
{
s[i]=*p;
i++;
}
p++;
}
s[i]='\0';
}

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// insert code here...

char stra[N],strb[N];
int i;

printf("请输入原始字符串a: ");
gets(stra);
printf("请输入删除字符串b: ");
gets(strb);

for(i=0;strb[i]!='\0';i++)
fun(stra,strb[i]);
printf("删除指定字符串b后的字符串a: ");
puts(stra);

[pool drain];
return 0;
}

C language (10进制转2,8,16进制)


#import
#import

void tran(int num, int k) {
int arr[8],i;
for(i=0;i<8;i++) {
arr[i] = num % k;
num=num/k;
if(num == 0)
break;
}
printf("转换为%d进制数为: ",k);

for(;i>=0;i--) {
switch (arr[i]) {
case 10:
printf("A");
break;
case 11:
printf("B");
break;
case 12:
printf("C");
break;
case 13:
printf("D");
break;
case 14:
printf("E");
break;
case 15:
printf("F");
break;
default:
printf("%d",arr[i]);
}
}
printf("\n\n\n");
}

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// insert code here...
NSLog(@"Hello, World!");

int num,choo;
loop: printf("请选择功能:0.退出 1.十进制转二进制 2.十进制转八进制 3.十进制转十六进制\n");
scanf("%d",&choo);
switch (choo)
{
case 1:
printf("请输入要转换的十进制数:");
scanf("%d",&num);
tran (num,2);
goto loop;
case 2:
printf("请输入要转换的十进制数:");
scanf("%d",&num);
tran (num,8);
goto loop;
case 3:
printf("请输入要转换的十进制数:");
scanf("%d",&num);
tran (num,16);
goto loop;
case 0:break;
default :
printf("输入有误!请重新输入!\n");
goto loop;
}

[pool drain];
return 0;
}

Monday, November 16, 2009

Amazing--iPhone

iPhone,THE MOBILE I am holding is a preemptive, multi- tasking computer with Unix, a graphical interface, GPS functionality, Wi-Fi, a ton of built-in libraries, and by the way, a cell phone. Amazing!

Saturday, November 14, 2009

OpenGL 学习资料

新的一轮挑战,OpenGL

很有用的两个学习链接
1.http://www.videotutorialsrock.com/index.php
2.http://nehe.gamedev.net/default.asp

Wednesday, November 11, 2009

Recursive C language

Here’s one version of a recursive function that calculates a factorial:

long factorial( long num ) {
if ( num > 1 )
num *= factorial( num - 1 );
return( num );
}


Find Bug with The LLVM/Clang Static Analyzer

Clang Static Analyzer

The Clang Static Analyzer consists of both a source code analysis framework and a standalone tool that finds bugs in C and Objective-C programs. The standalone tool is invoked from the command-line, and is intended to run in tandem with a build of a project or code base.

Both are 100% open source and are part of the Clang project.
Download :http://clang-analyzer.llvm.org/
Mac OS X

* Latest build (Universal binary, 10.5+): checker-227.tar.bz2 (built November 4, 2009)
* Installation and usage

Installation

Since scan-build is a command line tool it makes sense to install it into one of OS X’s pre-defined command line tool locations. We’ll put it in /usr/local/bin.

  1. Make sure that you’ve expanded checker-NN.tar.gz to your Downloads folder
  2. We’re going to be installing the checker binaries into your /usr/local/bin directory. Run the following command to ensure that this directory exists:
  3.  
    sudo mkdir -p /usr/local/bin
  4. Open Terminal.app and move the contents of checker-NN to the /usr/local/bin directory (remember to replace NN with the build number of your download):
    sudo mv ~/Downloads/checker-NN/* /usr/local/bin/
Run
The analyzer must be run after a xcodebuild clean command.

xcodebuild clean
scan-build -k -V xcodebuild

Monday, November 9, 2009

send Image through Email


UIImage *sendImg = [UIImage imageNamed:@"test.png"];
NSData *imageData = UIImagePNGRepresentation(sendImg);

NSString *dataStr = [testPurchase base64StringFromData:imageData length:[imageData length]];
//NSLog(dataStr);
//*
NSString *body = [@"" stringByAppendingFormat:@"Interpolate Chart", dataStr];
NSString *encoded = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *title = [[@"" stringByAppendingFormat:@"Interpolate: Function %@", @"test"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString * urlString = [@"" stringByAppendingFormat:@"mailto:wenxp2006@qq.com?subject=%@&body=%@", title, encoded];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];



//base 64 encoding
+ (NSString *) base64StringFromData: (NSData *)data length: (int)length
{
unsigned long ixtext, lentext;
long ctremaining;
unsigned char input[3], output[4];
short i, charsonline = 0, ctcopy;
const unsigned char *raw;
NSMutableString *result;

lentext = [data length];
if (lentext < 1)
return @"";
result = [NSMutableString stringWithCapacity: lentext];
raw = [data bytes];
ixtext = 0;

while (YES)
{
ctremaining = lentext - ixtext;
if (ctremaining <= 0)
break;
for (i = 0; i < 3; i++)
{
unsigned long ix = ixtext + i;
if (ix < lentext)
input[i] = raw[ix];
else
input[i] = 0;
}

output[0] = (input[0] & 0xFC) >> 2;
output[1] = ((input[0] & 0x03) << 4) | ((input[1] & 0xF0) >> 4);
output[2] = ((input[1] & 0x0F) << 2) | ((input[2] & 0xC0) >> 6);
output[3] = input[2] & 0x3F;
ctcopy = 4;
switch (ctremaining)
{
case 1:
ctcopy = 2;
break;
case 2:
ctcopy = 3;
break;
}

for (i = 0; i < ctcopy; i++)
[result appendString: [NSString stringWithFormat: @"%c", base64EncodingTable[output[i]]]];

for (i = ctcopy; i < 4; i++)
[result appendString: @"="];

ixtext += 3;
charsonline += 4;

if ((length > 0) && (charsonline >= length))
charsonline = 0;
}
return result;
}



static char base64EncodingTable[64] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};

Sunday, November 8, 2009

C simple DVD shop


#include
#include
#include
#include "dvdTracker2.h"


/**************************************************> main <*/
int main (int argc, const char * argv[]) {
char command;

gHeadPtr = NULL;
gTailPtr = NULL;

while ( (command = GetCommand() ) != 'q' ) {
switch( command ) {
case 'n':
AddToList( ReadStruct() );
break;
case 'l':
ListDVDs();
break;
}
}

printf( "Goodbye..." );

return 0;
}


/*******************************************> GetCommand <*/
char GetCommand( void )
{
char command;

do {
printf( "Enter command (q=quit, n=new, l=list): " );
scanf( "%c", &command );
Flush();
}
while ( (command != 'q') && (command != 'n')
&& (command != 'l') );

printf( "\n----------\n" );
return( command );
}


/*******************************************> ReadStruct <*/
struct DVDInfo *ReadStruct( void ) {
struct DVDInfo *infoPtr;
int num;

infoPtr = (struct DVDInfo *)malloc( sizeof( struct DVDInfo ) );

if ( NULL == infoPtr ) {
printf( "Out of memory!!! Goodbye!\n" );
exit( 0 );
}

printf( "Enter DVD Title: " );
fgets( infoPtr->title, kMaxTitleLength, stdin );
ReplaceReturnAtEndOfString( infoPtr->title );

printf( "Enter DVD Comment: " );
fgets( infoPtr->comment, kMaxCommentLength, stdin );
ReplaceReturnAtEndOfString( infoPtr->comment );

do {
num = 0;
printf( "Enter DVD Rating (1-10): " );
scanf( "%d", &num );
Flush();
}
while ( ( num < 1 ) || ( num > 10 ) );

infoPtr->rating = num;

printf( "\n----------\n" );

return( infoPtr );
}


/*******************************************> AddToList <*/
void AddToList( struct DVDInfo *curPtr ) {
struct DVDInfo *beforePtr;

/* First check to see if the list is empty */
if ( gHeadPtr == NULL )
InsertInList( NULL, curPtr );
else if ( curPtr->rating <= gHeadPtr->rating )
/* Next check to see if curPtr should be the new first item */
InsertInList( NULL, curPtr );
else {
/* Walk through the list till you find the first rating higher than us */
beforePtr = gHeadPtr;

while ( (beforePtr->next != NULL) &&
(beforePtr->next->rating < curPtr->rating) ) {
beforePtr = beforePtr->next;
}
InsertInList( beforePtr, curPtr );
}
}


/*******************************************> InsertInList <*/
void InsertInList( struct DVDInfo *afterMeDVDPtr, struct DVDInfo *newDVDPtr )
{
if ( afterMeDVDPtr == NULL ) {
/* This means we want to insert the new one as the first in the list */
newDVDPtr->next = gHeadPtr;
gHeadPtr = newDVDPtr;
if ( gTailPtr == NULL )
gTailPtr = newDVDPtr;
}
else if ( afterMeDVDPtr == gTailPtr ) {
/* This means we want to insert the new one as the last in the list */
gTailPtr->next = newDVDPtr;
newDVDPtr->next = NULL;
gTailPtr = newDVDPtr;
}
else {
newDVDPtr->next = afterMeDVDPtr->next;
afterMeDVDPtr->next = newDVDPtr;
}
}


/*******************************************> ListDVDs <*/
void ListDVDs( void ) {
struct DVDInfo *curPtr;

if ( NULL == gHeadPtr ) {
printf( "No DVDs have been entered yet...\n" );
printf( "\n----------\n" );
} else {
for ( curPtr=gHeadPtr; curPtr!=NULL; curPtr = curPtr->next ) {
printf( "Title: %s\n", curPtr->title );
printf( "Comment: %s\n", curPtr->comment );
printf( "Rating: %d\n", curPtr->rating );

printf( "\n----------\n" );
}
}
}


/***********************> ReplaceReturnAtEndOfString <*/
void ReplaceReturnAtEndOfString( char *theString ) {
int length = strlen( theString );

theString[ length - 1 ] = '\0';
}


/*******************************************> Flush <*/
void Flush( void ) {
while ( getchar() != '\n' )
;
}

Thursday, November 5, 2009

UITableView's Scroll range


UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, intersectionFrame.size.height, 0);
[self.tableView setContentInset:insets];
[self.tableView setScrollIndicatorInsets:insets];


UIEdgeInsets UIEdgeInsetsMake (
CGFloat top,
CGFloat left,
CGFloat bottom,
CGFloat right
);

[self.tableView setContentInset:insets];
The content of tableView displayed in the insets(Rect)

[self.tableView setScrollIndicatorInsets:insets];
The Scroll range of the tableView

Camera and ActionSheet API of iPhone







click a button raise an actionsheet

- (IBAction)addPhoto:(id)sender {
UIActionSheet *cameraSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"TakePicture",@"ChooseFromLibrary",nil];
cameraSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[cameraSheet showInView:self.view];
[cameraSheet release];
}

Delegation methods of ActionSheet

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
} else {
[actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
}
} else if (buttonIndex == 1) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}

else if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}

else{
[actionSheet dismissWithClickedButtonIndex:buttonIndex animated: YES];
}
}

}


Delegate methods of UIImagePickerControllerDelegate

#pragma mark -
#pragma mark UIImagePickerControllerDelegate Methods

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
[self dismissModalViewControllerAnimated:YES];
}

Wednesday, November 4, 2009

C language Octal to ASCII printable characters

32 to 47 ---> !"#$%&'()*+,-./
48 to 57 ---> 0123456789
58 to 64 ---> :;<=>?@
65 to 90 ---> ABCDEFGHIJKLMNOPQRSTUVWXYZ
91 to 96 ---> [\]^_`
97 to 122 ---> abcdefghijklmnopqrstuvwxyz
123 to 126 ---> {|}~

C language (char,short,int,long)


int main (int argc, const char * argv[]) {
printf( "sizeof( char ) = %d\n", (int)sizeof( char ) );
printf( "sizeof( short ) = %d\n", (int)sizeof( short ) );
printf( "sizeof( int ) = %d\n", (int)sizeof( int ) );
printf( "sizeof( long ) = %d\n", (int)sizeof( long ) );

return 0;
}



sizeof( char ) = 1
sizeof( short ) = 2
sizeof( int ) = 4
sizeof( long ) = 4

C language (float,double,longDouble)


int main (int argc, const char * argv[]) {
float myFloat;
double myDouble;
long double myLongDouble;

myFloat = 12345.67890123456789F;
myDouble = 12345.67890123456789;
myLongDouble = 12345.67890123456789L;

printf( "sizeof( float ) = %d\n", (int)sizeof( float ) );
printf( "sizeof( double ) = %d\n", (int)sizeof( double ) );
printf( "sizeof( long double ) = %d\n\n", (int)sizeof( long double ) );

printf( "myFloat = %f\n", myFloat );
printf( "myDouble = %f\n", myDouble );
printf( "myLongDouble = %Lf\n\n", myLongDouble );

printf( "myFloat = %25.16f\n", myFloat );
printf( "myDouble = %25.16f\n", myDouble );
printf( "myLongDouble = %25.16Lf\n\n", myLongDouble );

printf( "myFloat = %10.1f\n", myFloat );
printf( "myFloat = %.2f\n", myFloat );
printf( "myFloat = %.12f\n", myFloat );
printf( "myFloat = %.9f\n\n", myFloat );

printf( "myFloat = %e\n\n", myFloat );

myFloat = 100000;
printf( "myFloat = %g\n", myFloat );

myFloat = 1000000;
printf( "myFloat = %g\n", myFloat );

return 0;
}


result

sizeof( float ) = 4
sizeof( double ) = 8
sizeof( long double ) = 16

myFloat = 12345.678711
myDouble = 12345.678901
myLongDouble = 12345.678901

myFloat = 12345.6787109375000000
myDouble = 12345.6789012345670926
myLongDouble = 12345.6789012345678902

myFloat = 12345.7
myFloat = 12345.68
myFloat = 12345.678710937500
myFloat = 12345.678710938

myFloat = 1.234568e+04

myFloat = 100000
myFloat = 1e+06

C