Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Casting 如何从浮点数中获得精确整数?_Casting_Scheme_Rounding - Fatal编程技术网

Casting 如何从浮点数中获得精确整数?

Casting 如何从浮点数中获得精确整数?,casting,scheme,rounding,Casting,Scheme,Rounding,我需要使用带有整数参数的random函数,我从理论上可以返回double的运算中得到整数参数。因此,我想为此使用一些石膏/圆。我试过了 (random (round 10.0)) (random (floor 10.0)) 但它抛出了如下异常 random: expects argument of type <exact integer in [1, 4294967087] or pseudo-random-generator>; given 10.0 random:需要类型为的

我需要使用带有整数参数的
random
函数,我从理论上可以返回double的运算中得到整数参数。因此,我想为此使用一些石膏/圆。我试过了

(random (round 10.0))
(random (floor 10.0))
但它抛出了如下异常

random: expects argument of type <exact integer in [1, 4294967087] or pseudo-random-generator>; given 10.0
random:需要类型为的参数;给定10.0
我使用DrRacket作为解释器。

尝试
(随机(地板->精确10.0))
(随机(不精确->精确(第10.0轮))

可以使用任意圆角(地板/圆角/截断/天花板)

这里讨论了这一点:
(搜索“不精确->精确”)

突然,我的方案中没有这样的功能(
expand:unbound identifier in module in:floor->exact
)@Stas:这行吗<代码>(随机(不精确->精确(第10.0轮))@Stas-请参阅我提供的链接中的不精确到精确的翻译部分。@Stas-如果您的硬代码10.0为常量,则是。我不确定“不精确->精确”是否适用于尚未存在的整数值,因此我假设您也需要
舍入
。@DVK,是的。你是对的,它只适用于整数值。在我的例子中,我使用这些数字,但它们表示为浮点。像这样
(随机(不精确->精确(/30.0 1.5))