| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1910 人关注过本帖
标题:求教!哪个计算结果正确???
取消只看楼主 加入收藏
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
结帖率:97.06%
收藏
已结贴  问题点数:30 回复次数:3 
求教!哪个计算结果正确???
1:qsort函数, return *( int *)b > *(int *)a ? 1 : -1 和 return (( int *)b)[0] > ((int *)a)[0] ? 1 : -1的区别?

2:对加减乘除计算结果有什么影响?哪个正确?

  

[此贴子已经被作者于2017-2-28 15:50编辑过]

搜索更多相关主题的帖子: return 影响 
2017-02-28 13:36
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 
经过试验:

qsort函数, return *( int *)b > *(int *)a ? 1 : -1 ;

排序后,计算正确;
2017-02-28 15:51
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 
回复 6楼 rjsp
可是,在计算过程中,会出现两种不同的计算结果;只能人工计算判断哪个方法正确了!

例如:


计算结果1               计算结果2
0.855263                1
0.873563                0.837037
0.747126                0.837037
0.955556                1
0.697248                1
0.855263                1
0.747126                1
1                        0.727434
0.873563                1
0.697248                1
               
3.457421                0.997528
1.113855                0.985623
1.188587                0.981072
1.259307                0.973349
1.078908                0.978193
3.137956                0.987309
1.517089                0.993468
2.385143                0.928318
-0.240351                0.973349
1.30704                    0.978193
               
Press any key to continue                Press any key to continue
2017-02-28 16:09
宇宙规律
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:232
专家分:128
注 册:2014-5-7
收藏
得分:0 
回复 9楼 azzbcc
1:如果一样,那么省心不用二选一了;
2:用两个方法分别计算,计算结果不一样;
例如:

方法一:                          方法二:
3.000000  3.000000                        3.000000  3.560000        
                                
0.836066                        0.379747        
0.973958                        0.078947        
0.566474                        0.36611        
0.952919                        0.203273        
0.732824                        0.883402        
0.810247                        0.474474        
0.475907                        0.139676        
0.688853                        0.488304        
1                                0.353742        
0.863686                        0.860957        
                                
4.000000  4.000000(错误!)                        4.000000  2.000000    (正确!)   
                                
0.133929                        0.342857        
0.607143                        0.178571        
0.421053                        0.106667        
0.0058                            0.4        
1                                0.725        
1                                0.833333        
0.1875                            0.256684        
0.003                            0.4        
1                                0.296296        
1                                0.652174        
                                
7.000000  7.000000                        7.000000  3.465753        
                                
0.98926                            2.530189        
0.992717                        1.553683        
0.956527                        1.058629        
0.935797                        1.445122        
0.984023                        1.00839        
0.997038                        20.298866        
0.982813                        3.207247        
0.948814                        2.241864        
0.959189                        -0.202519        
0.984023                        1.009544        
                                
3.250000  3.250000                        3.250000  3.500000        
                                
0.832117                        0.811487        
0.809524                        0.322597        
0.835592                        0.253333        
0.944828                        0.767442        
0.845478                        0.904401        
1                                0.811487        
0.850556                        0.724638        
0.645443                        0.668966        
0.824746                        0.175758        
0.880597                        0.585284        
                                
Press any key to continue                        Press any key to continue        
                                


[此贴子已经被作者于2017-2-28 17:49编辑过]

2017-02-28 17:47
快速回复:求教!哪个计算结果正确???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.063091 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved