相关疑难解决方法(0)

分割两个Int值以获得Float的正确方法是什么?

我想Int在Haskell中划分两个值并将结果作为a Float.我尝试这样做:

foo :: Int -> Int -> Float
foo a b = fromRational $ a % b
Run Code Online (Sandbox Code Playgroud)

但是GHC(版本6.12.1)告诉我"无法将预期类型'Integer'与推断类型'Int'相匹配"关于a表达式中的内容.

我理解为什么:fromRational调用需要(%)生成一个Ratio Integer,所以操作数需要是类型Integer而不是Int.但是我正在划分的值远远没有接近Int范围限制,因此使用任意精度的bignum类型似乎有点过分.

这样做的正确方法是什么?我应该只是打电话toInteger给我的操作数,还是有一种(%)我不了解的更好的方法(可能不涉及和比率)?

floating-point haskell types integer

29
推荐指数
1
解决办法
2万
查看次数

Haskell将Float转换为Int

我还是新手,并试图创建一个在函数中使用的列表,并希望尽可能小地保留它,这恰好是logBase x y.但是我无法将logBase变成我可以在此列表中使用的东西.

[1 ..(logBase xy)]

有什么建议?

floating-point int haskell

10
推荐指数
2
解决办法
2万
查看次数

Haskell int浮动,char浮动

haskell中有一个函数,它从int转换为float,从char转换为float?

我知道有一个函数可以从char转换为int,int转换为char.

floating-point int haskell

5
推荐指数
2
解决办法
9684
查看次数

标签 统计

floating-point ×3

haskell ×3

int ×2

integer ×1

types ×1