gpt4 book ai didi

function - 方案中的签名功能?

转载 作者:行者123 更新时间:2023-12-03 06:23:44 25 4
gpt4 key购买 nike

Scheme有符号功能吗?我找不到任何相关信息。

我将符号函数定义为当 x<0 时产生 -1、当 x=0 时产生 0、当 x>0 时产生 1 的函数。

最佳答案

只需使用内置的 sgn程序:

(sgn -10)
=> -1
(sgn 10)
=> 1
(sgn 0)
=> 0

如果您想知道如何实现它......

(define (sign n)
(cond ((negative? n) -1)
((positive? n) 1)
(else 0)))

关于function - 方案中的签名功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8782685/

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