gpt4 book ai didi

c# - f# 和 c# 获得基础数学的不同答案

转载 作者:行者123 更新时间:2023-11-30 17:29:52 25 4
gpt4 key购买 nike

我有 f# 模块

open System

module Scores =

let DbToContinuous input = (((input / 1000) - 1) * 100) + (input % 1000)

这是整个模块(到目前为止)

我有一个要替换的 C# 函数(看起来非常相似)。

    private static int DbToRealScore(int dbScore)
{
return ((dbScore / 1000) - 1) * 100 + (dbScore % 1000);
}

但是,有一点不对劲。两者没有产生相同的结果。

切换回 C# 版本,我增加了以下内容:

private static int DbToRealScore(int dbScore)
{

var x = Scores.DbToContinuous(dbScore);
var y = ((dbScore / 1000) - 1) * 100 + (dbScore % 1000);

if (x != y)
{
throw new Exception($"Math error: [input: {dbScore}, x: {x}, y:{y}]");
}

return y;
}

对于 4100 的输入,我收到错误消息 Math error: [input: 4100, x: 500, y:400],表明 f# 版本100 太大了。它没有减去 1。

更奇怪的是,当我使用 f# 交互式控制台时,f# 代码按预期工作...

> let y x = (((x / 1000) - 1) * 100) + (x % 1000);;
val y : x:int -> int

> y 4000;;
val it : int = 300

> y 4100;;
val it : int = 400

如能提供有关我如何获得这两个不同答案的任何信息,我们将不胜感激。

最佳答案

在 f# 项目上运行 clean 而不是解决方案来修复它。我不知道为什么它不能用解决方案正确清理,但清理项目会导致它重建并获得正确的结果。

关于c# - f# 和 c# 获得基础数学的不同答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50627277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com