蜂巢 - 双精度

时间:2017-04-12 07:25:43

标签: hadoop hive

我一直在做蜂巢,发现了一些奇特的东西。基本上,当使用double作为列的数据类型时,我们不需要指定任何精度(hive根据值动态获取精度)。但是,这是问题所在。每当我的值在小数点后面的2和7时,我看到返回值也会改变精度中位置的数量。

让我用简单的例子清楚说明。

hive> select cast('34.2234' + '32.6554' -3.1 as double);
OK
63.7788
Time Taken 0.077 seconds, Fetched: 1 row(s)

当我在小数点后使用1(减去3.1中的1)时,我可以看到结果似乎很好。但是当减法给出3.2或3.7时,我看到下面的变化

使用3.2

hive> select cast('34.2234' + '32.6554' -3.2 as double);
OK
63.678799999999995
Time Taken 0.077 seconds, Fetched: 1 row(s)

使用3.7时

hive> select cast('34.2234' + '32.6554' -3.7 as double);
OK
63.178799999999995
Time Taken 0.077 seconds, Fetched: 1 row(s)

虽然结果似乎是正确的,但为什么在这种情况下精度会发生变化。当我们在小数点之前使用任何值并且在它之后仅使用2或7时(如4.2,4.7,3.2,2.7等),它是相同的。 2和7特有的是它将精度改为15值,为什么不改为其他值。

2 个答案:

答案 0 :(得分:0)

这就是浮点运算的样子

class SearchView: UIView,
              UICollectionViewDelegateFlowLayout,
              UICollectionViewDataSource {

var collectionView: UICollectionView!


 ----


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)

    let myViewController: MyViewController = mainStoryBoard.instantiateViewController(withIdentifier: “MyViewController") as! MyViewController

//      let currentController = self.getCurrentViewController()

//        currentController?.navigationController?.pushViewController(myViewController, animated: true)

// self.parentViewController.navigationController.pushViewController(myViewController, animated: true) 


    let vc = self.window?.rootViewController

    let navController = vc?.navigationController

    navController?.pushViewController(myViewController, animated: true)
  

DOUBLE(8字节双精度浮点数

     

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types

如果您想要准确/可预测的内容,请使用hive> select 1.1 + 0.1; OK 1.2000000000000002

decimal

答案 1 :(得分:0)

我认为您将计算精度与显示的小数混淆。

Hive将始终使用相同的计算精度,但不显示尾随零。

因此它有时只返回几个小数,但是当你使用一个在浮点数集合中不适合的数字时,它只会显示小数直到结束。