当前位置: 首页 > news >正文

网站建设小技巧什么软件推广效果好

网站建设小技巧,什么软件推广效果好,金昌做网站,少儿编程机构一、源码 这段代码是用Rust语言实现的一个类型系统级别的算术取负运算(-运算符),通过Rust的特性(trait)系统来实现。 use core::ops::{Not, Neg}; use crate::number::{Z0, P1, N1, B0, B1, NonZero, Float, Var, Pr…

一、源码

这段代码是用Rust语言实现的一个类型系统级别的算术取负运算(-运算符),通过Rust的特性(trait)系统来实现。

use core::ops::{Not, Neg};
use crate::number::{Z0, P1, N1, B0, B1, NonZero, Float, Var, PrimitiveInt, Primitive};// ==================== 算术取负(-运算符) ====================
impl Neg for Z0 { // Z0 (0) 的取负type Output = Z0;fn neg(self) -> Self::Output {Z0}
}impl Neg for P1 {type Output = N1;fn neg(self) -> Self::Output {N1}
}impl Neg for N1 { // N1 (-1) 的取负,用P1替换B1<Z0>type Output = P1;fn neg(self) -> Self::Output {P1}
}impl<H: NonZero + Neg> Neg for B0<H>{type Output = B0<H::Output>;fn neg(self) -> Self::Output {B0::new()}
}impl<H: NonZero + Not> Neg for B1<H>{type Output = B1<H::Output>;fn neg(self) -> Self::Output {B1::new()}
}// 浮点数取反
impl<Mantissa: Neg, Exponent> Neg for Float<Mantissa, Exponent> {type Output = Float<Mantissa::Output, Exponent>;fn neg(self) -> Self::Output {Float::new()}
}// -Var<T> = Var<-T>
impl<T: Primitive + Neg> Neg for Var<T> {type Output = Var<<T as Neg>::Output>;#[inline(always)]fn neg(self) -> Self::Output {Var(-self.0)}
}

二、源码分析

  1. 导入依赖
use core::ops::{Not, Neg};
use crate::number::{Z0, P1, N1, B0, B1, NonZero, Float, Var, PrimitiveInt, Primitive};
  • Neg trait:这是Rust标准库中的算术取负运算符trait。

  • Not trait:这是Rust标准库中的位取反运算符trait(虽然这里主要用Neg,但Not可能在其他地方用到)。

  • 其他类型(Z0, P1, N1, B0, B1, Float, Var等)是自定义的类型,用于表示不同的数字或数值。

  1. 基础类型实现
    这部分实现了基本数字类型的算术取负运算。
a. 零取负
impl Neg for Z0 { // Z0 (0) 的取负type Output = Z0;fn neg(self) -> Self::Output {Z0}
}
  • Z0表示数字0。

  • 算术取负运算-0的结果仍然是0(用Z0表示)。

b. 正一取负
impl Neg for P1 {type Output = N1;fn neg(self) -> Self::Output {N1}
}
  • P1表示数字1。

  • 算术取负运算-1的结果是-1(用N1表示)。

c. 负一取负
impl Neg for N1 { // N1 (-1) 的取负,用P1替换B1<Z0>type Output = P1;fn neg(self) -> Self::Output {P1}
}
  • N1表示数字-1。

  • 算术取负运算-(-1)的结果是1(用P1表示)。

  1. 递归类型实现
    这部分处理二进制数的算术取负,通过递归的方式处理更高位的二进制数。
a. 二进制0前缀取负
impl<H: NonZero + Neg> Neg for B0<H>{type Output = B0<H::Output>;fn neg(self) -> Self::Output {B0::new()}
}
  • B0表示一个以0为前缀的二进制数(例如B0表示10,即-2)。

取负后变为B0<-H>(即前缀0保持不变,剩余部分取负)。

b. 二进制1前缀取负

impl<H: NonZero + Not> Neg for B1<H>{type Output = B1<H::Output>;fn neg(self) -> Self::Output {B1::new()}
}
  • B1表示一个以1为前缀的二进制数(例如B1表示01,即1)。

  • 取负后变为B1<!H>(即前缀1保持不变,剩余部分取反,这里用Not可能是为了优化或特殊处理)。

  1. 浮点数取负
impl<Mantissa: Neg, Exponent> Neg for Float<Mantissa, Exponent> {type Output = Float<Mantissa::Output, Exponent>;fn neg(self) -> Self::Output {Float::new()}
}
  • Float<Mantissa, Exponent>表示一个浮点数,由尾数(Mantissa)和指数(Exponent)组成。

  • 取负运算只对尾数部分取负,指数部分保持不变。

  1. 变量类型取负
impl<T: Primitive + Neg> Neg for Var<T> {type Output = Var<<T as Neg>::Output>;#[inline(always)]fn neg(self) -> Self::Output {Var(-self.0)}
}
  • Var是一个包装类型,用于表示变量。

  • 如果T实现了Neg,则Var也可以进行算术取负运算,结果为Var<-T>。

三、总结

这段代码实现了一个类型级别的算术取负运算系统,支持:

  1. 基本数字(0、1、-1)的取负。

  2. 二进制数的递归取负(B0和B1)。

  3. 浮点数的取负(只对尾数取负)。

  4. 变量类型的取负。

这种技术常用于类型安全的数学库或嵌入式DSL(领域特定语言)中,确保编译期就能完成某些计算或检查。

http://www.hengruixuexiao.com/news/39598.html

相关文章:

  • 昆明seo网站建设电商运营基本知识
  • 网站建设的行业建设网站的网络公司
  • 竞价网站同时做优化可以吗站长之家app下载
  • 一个网站锚文本可以做几个中国新冠一共死去的人数
  • tk注册网站5118关键词查询工具
  • 免费网页游戏源码济南网站优化培训
  • 河北省建设厅网站电话市场营销策略有哪些
  • 网站后期维护很难吗百度的网页地址
  • 四平网站制作免费网站安全软件大全
  • WordPress禁止多ipseo 360
  • ppt免费下载seo公司排名
  • 咨询行业网站开发推广平台免费b2b网站大全
  • 做企业官网的流程seo专业课程
  • 步步高网站建设报告百度seo排名原理
  • 网站建设中图标搜索引擎推广方法
  • 杭州市拱墅区疫情最新消息温州seo招聘
  • 沈阳餐饮网站建设百度小程序优化排名
  • 品牌设计logo vi设计最新seo教程
  • 关于网络编辑作业做网站栏目新闻的ppt关键词优化资讯
  • wordpress 多语言网站抖音信息流广告怎么投放
  • mip网站设计电子商务营销方法
  • 北京门头沟住房和城乡建设委员会网站百度客服电话人工服务热线电话
  • 网站建设专业学什么市场推广seo职位描述
  • 怎样用axure做网站上的注册找回今日头条
  • 百度竞价是什么意思seo点击排名源码
  • 可以用什么做网站登录页面站长之家点击进入
  • 重庆商城网站建设公司东莞网络推广策略
  • 个人手机版网站app怎么做淘宝seo是什么
  • 汉口网站建设 优帮云seo手机关键词网址
  • 做网站出路免费seo网站自动推广