小编Phi*_*ipp的帖子

舍入到Haskell中的特定位数

我正在尝试创建一个函数来将浮点数舍入到定义的数字长度.到目前为止我得出的是:

import Numeric;

digs :: Integral x => x -> [x] <br>
digs 0 = [] <br>
digs x = digs (x `div` 10) ++ [x `mod` 10]

roundTo x t = let d = length $ digs $ round x <br>
                  roundToMachine x t = (fromInteger $ round $ x * 10^^t) * 10^^(-t)
              in roundToMachine x (t - d)
Run Code Online (Sandbox Code Playgroud)

我正在使用该digs函数来确定逗号之前的数字位数以优化输入值(即将所有内容移到逗号之外,因此1.234变为0.1234 * 10^1)

roundTo函数似乎适用于大多数输入,但是对于某些输入,我得到奇怪的结果,例如roundTo 1.0014 4生成1.0010000000000001而不是1.001 …

math haskell

9
推荐指数
2
解决办法
4380
查看次数

SQLCriterion ArgumentOutOfRangeException

创建 SQLCriterion 的正确语法是什么?

我有以下代码:

var sqlCriterion = new SQLCriterion(
                new SqlString("{alias}.Id IN (SELECT Id FROM dbo.fGetSomeIds(?1, ?2))"),
                new object[] { "param1", "param2" },
                new IType[] { NHibernateUtil.String, NHibernateUtil.String });

query.Where(sqlCriterion);
Run Code Online (Sandbox Code Playgroud)

其中查询是我的 QueryOver 实例(用 NHibernateSession 创建)

当我调用 query.List() 时,出现以下异常:

Index was out of range. Must be non-negative and less than the size of the collection parameter name:index 
Run Code Online (Sandbox Code Playgroud)

这是在 NHibernate.Criterion.SQLCriterion.ToSqlString(..)

我的 SQLCriterion 构造函数的语法是错误的还是我遗漏了其他东西?

.net c# nhibernate queryover

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

标签 统计

.net ×1

c# ×1

haskell ×1

math ×1

nhibernate ×1

queryover ×1