gpt4 book ai didi

scheme - 如何在Racket中将实数转换为精确整数?

转载 作者:行者123 更新时间:2023-12-04 17:45:35 25 4
gpt4 key购买 nike

如何将20.2格式的值转换为(random ...)接受的值?

我已经尝试过这些:

;; x defined by some earlier maths and of form 20.2

(random (round x))
(random (floor x))

但是两者都返回:
random: contract violation
expected: (or/c (integer-in 1 4294967087) pseudo-random-generator?)
given: 20.0

最佳答案

这些也有效,根据documentation,它们只是您使用方法的简写:

(random (exact-round x))
(random (exact-floor x))

关于scheme - 如何在Racket中将实数转换为精确整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35381053/

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