Golang的脱身功能 [英] Bodiless function in Golang

查看:133
本文介绍了Golang的脱身功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读 math / floor.go 的源代码, ,从第13行开始,我读了一些如下代码:

Reading the source code of math/floor.go, starting from line 13, I read some code like this:

func Floor(x float64) float64

func floor(x float64) float64 {
    if x == 0 || IsNaN(x) || IsInf(x, 0) {
        return x
    }
    if x < 0 {
        d, fract := Modf(-x)
        if fract != 0.0 {
            d = d + 1
        }
        return -d
    }
    d, _ := Modf(x)
    return d
}

看来 func Floor 没有正文。我试图将这些代码复制并粘贴到我的go文件中。它不会编译。错误消息是缺少函数体。所以我的问题是:Go的语法是一个合法的身体语言吗?感谢。

It seems the func Floor has no body. I tried to copy and paste these code in my go file. it doesn't compile. The error message is missing function body. So my question is: is a bodiless function legal in Go's syntax? Thanks.

推荐答案

这是函数如何在汇编中实现的方式。您可以在 floor_ARCH.s 中找到程序集实现(例如:AMD64 )文件。

It's the way how functions are implemented in assembly. You find the assembly implementation in the floor_ARCH.s (e.g.: AMD64) files.

引用 spec

To quote the spec:


函数声明可以省略body。这样的声明提供了在Go外部实现的函数的签名,例如汇编例程。

这篇关于Golang的脱身功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆