正弦函数在哪里? [英] Where is the sine function?

查看:79
本文介绍了正弦函数在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题:sin()在哪里?我已经搜索过,仅在Rust文档中发现有 require 的特征std::num::Float,但是没有实现的特征.

Simple question: Where is sin()? I've searched and only found in the Rust docs that there are traits like std::num::Float that require sin, but no implementation.

推荐答案

Float特征已被删除,并且这些方法现在是这些类型的固有实现.这意味着访问数学函数的类型有所减少:

The Float trait was removed, and the methods are inherent implementations on the types now. That means there's a bit less typing to access math functions:

fn main() {
    let val: f32 = 3.14159;
    println!("{}", val.sin());
}

但是,如果3.14159.sin()是指32位或64位数字,则模棱两可,因此您需要明确指定它.上面,我设置了变量的类型,但是您也可以使用类型后缀:

However, it's ambiguous if 3.14159.sin() refers to a 32- or 64-bit number, so you need to specify it explicitly. Above, I set the type of the variable, but you can also use a type suffix:

fn main() {
    println!("{}", 3.14159f64.sin());
}

您还可以使用

这篇关于正弦函数在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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