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

制作网站需要什么技术知末网su模型免费下载

制作网站需要什么技术,知末网su模型免费下载,项目网站建设应入哪个科目,网站模板软件一、源码 这段代码实现了一个类型级别的除法运算系统,主要用于处理不同类型的数值在编译期间进行的除法操作。它使用了Rust的类型系统和trait来实现编译时的计算。 use core::ops::{Neg, Div};use super::basic::{Z0, B0, B1, P1, N1}; use crate::constant::{Int…

一、源码

这段代码实现了一个类型级别的除法运算系统,主要用于处理不同类型的数值在编译期间进行的除法操作。它使用了Rust的类型系统和trait来实现编译时的计算。

use core::ops::{Neg, Div};use super::basic::{Z0, B0, B1, P1, N1};
use crate::constant::{Integer, NonZero};
use crate::variable::{Var, Numeric};// ========== Basic Type Division Operations ==========
// ========== 基本类型除法运算 ==========// ========== 0 / All ===========
// Division of zero by any non-zero type
// 0 除以任何非零类型// 0 / 0 is illegal and not implemented
// 0 / 0 非法,未实现// 0 / NonZero = 0
impl<I: NonZero> Div<I> for Z0 {type Output = Self;#[inline(always)]fn div(self, _rhs: I) -> Self::Output {self  // 0 / any non-zero = 0}
}// ========== 1 / All ===========
// Division of one by various types
// 1 除以各种类型// 1 / 0 is illegal and not implemented
// 1 / 0 非法,未实现// 1 / 1 = 1
impl Div<P1> for P1 {type Output = Self;#[inline(always)]fn div(self, _rhs: Self) -> Self::Output {P1}
}// 1/-1=-1
impl Div<N1> for P1 {type Output = N1;#[inline(always)]fn div(self, _rhs: N1) -> Self::Output {N1}
}// 1 / B0 has precision loss, returns f64
// 1 / B0 有精度损失,返回f64
impl<H:NonZero> Div<B0<H>> for P1 {type Output = f64;fn div(self, _: B0<H>) -> f64 {f64::from(1) / f64::from(B0::<H>::to_i32())}
}// 1 / B1 has precision loss, returns f64
// 1 / B1 有精度损失,返回f64
impl<H:NonZero> Div<B1<H>> for P1 {type Output = f64;fn div(self, _: B1<H>) -> f64 {f64::from(1) / f64::from(B1::<H>::to_i32())}
}// ========== -1 / All ===========
// Division of negative one by various types
// -1 除以各种类型// -1 / 0 is illegal and not implemented
// -1 / 0 非法,未实现// -1 / 1 = -1
impl Div<P1> for N1 {type Output = Self;#[inline(always)]fn div(self, _rhs: P1) -> Self::Output {N1}
}// -1/-1=1
impl Div<N1> for N1 {type Output = P1;#[inline(always)]fn div(self, _rhs: N1) -> Self::Output {P1}
}// -1 / B0 has precision loss, returns f64
// -1 / B0 有精度损失,返回f64
impl<H:NonZero> Div<B0<H>> for N1 {type Output = f64;fn div(self, _: B0<H>) -> f64 {f64::from(-1) / f64::from(B0::<H>::to_i32())}
}// -1 / B1 has precision loss, returns f64
// -1 / B1 有精度损失,返回f64
impl<H:NonZero> Div<B1<H>> for N1 {type Output = f64;fn div(self, _: B1<H>) -> f64 {f64::from(-1) / f64::from(B1::<H>::to_i32())}
}// ========== B0 / All ===========
// Division of binary type ending with 0 by various types
// 以0结尾的二进制类型除以各种类型// B0 / 0 is illegal and not implemented
// B0 / 0 非法,未实现// B0 / 1 = B0
impl<H: NonZero> Div<P1> for B0<H> {type Output = Self;#[inline(always)]fn div(self, _rhs: P1) -> Self::Output {self}
}// B0/-1=-B0
impl<H: NonZero> Div<N1> for B0<H>
where B0<H>: Neg,
{type Output = <B0<H> as Neg>::Output;#[inline(always)]fn div(self, _rhs: N1) -> Self::Output {-self}
}// B0 / B0 has precision loss, returns f64
// B0 / B0 有精度损失,返回f64
impl<H1:NonZero, H2:NonZero> Div<B0<H2>> for B0<H1> {type Output = f64;fn div(self, _: B0<H2>) -> f64 {f64::from(B0::<H1>::to_i32()) / f64::from(B0::<H2>::to_i32())}
}// B0 / B1 has precision loss, returns f64
// B0 / B1 有精度损失,返回f64
impl<H1:NonZero, H2:NonZero> Div<B1<H2>> for B0<H1> {type Output = f64;fn div(self, _: B1<H2>) -> f64 {f64::from(B0::<H1>::to_i32()) / f64::from(B1::<H2>::to_i32())}
}// ========== B1 / All ===========
// Division of binary type ending with 1 by various types
// 以1结尾的二进制类型除以各种类型// B1 / 0 is illegal and not implemented
// B1 / 0 非法,未实现// B1 / 1 = B1
impl<H: NonZero> Div<P1> for B1<H> {type Output = Self;#[inline(always)]fn div(self, _rhs: P1) -> Self::Output {self}
}// B1 / -1=-B1
impl<H: NonZero> Div<N1> for B1<H>
where B1<H>: Neg,
{type Output = <B1<H> as Neg>::Output;#[inline(always)]fn div(self, _rhs: N1) -> Self::Output {-self}
}// B1 / B0 has precision loss, returns f64
// B1 / B0 有精度损失,返回f64
impl<H1:NonZero, H2:NonZero> Div<B0<H2>> for B1<H1> {type Output = f64;fn div(self, _: B0<H2>) -> f64 {f64::from(B1::<H1>::to_i32()) / f64::from(B0::<H2>::to_i32())}
}// B1 / B1 has precision loss, returns f64
// B1 / B1 有精度损失,返回f64
impl<H1:NonZero, H2:NonZero> Div<B1<H2>> for B1<H1> {type Output = f64;fn div(self, _: B1<H2>) -> f64 {f64::from(B1::<H1>::to_i32()) / f64::from(B1::<H2>::to_i32())}
}// Quotient type alias
// 商类型别名
pub type Quot<A, B> = <A as Div<B>>::Output;// ========== Division with Var<T> ==========
// ========== 与Var<T>的除法运算 ==========// ========== 0 / Var<T> ==========
impl<T: Numeric + PartialEq> Div<Var<T>> for Z0 {type Output = Self;fn div(self, rhs: Var<T>) -> Self::Output {assert!(rhs.0 != T::from(0), "division by zero");self}
}// ========== 1 / Var<T> ==========
impl<T: Numeric> Div<Var<T>> for P1 {type Output = Var<T>;#[inline(always)]fn div(self, rhs: Var<T>) -> Self::Output {Var(T::from(1) / rhs.0)}
}// ========== -1 / Var<T> ==========
impl<T: Numeric> Div<Var<T>> for N1{type Output = <Var<T> as Neg>::Output;#[inline(always)]fn div(self, rhs: Var<T>) -> Self::Output {Var(T::from(-1) / rhs.0)}
}// ========== B0 / Var<T> ==========
impl<H: NonZero, T:Numeric> Div<Var<T>> for B0<H>
where B0<H>: Integer,Var<T>: Div<Var<T>>,
{type Output = Var<T>;#[inline(always)]fn div(self, rhs: Var<T>) -> Self::Output {Var(T::from(B0::<H>::to_i32()) / rhs.0)}
}// ========== B1 / Var<T> ==========impl<H: NonZero, T:Numeric> Div<Var<T>> for B1<H>
where B1<H>: Integer,Var<T>: Div<Var<T>>,
{type Output = Var<T>;#[inline(always)]fn div(self, rhs: Var<T>) -> Self::Output {Var(T::from(B1::<H>::to_i32()) / rhs.0)}
}

二、主要组成部分

  1. 基本类型定义
    代码中使用了以下基本类型:
  • Z0: 表示数字0

  • P1: 表示数字+1

  • N1: 表示数字-1

  • B0: 表示以0结尾的二进制数(如2=0b10)

  • B1: 表示以1结尾的二进制数(如3=0b11)

  1. 核心trait实现
    代码为这些类型实现了Div trait(除法运算),主要分为以下几类:
0的除法
  • 0 / 非零类型 = 0

  • 0 / 0 未实现(因为除零非法)

1的除法
  • 1 / 1 = 1

  • 1 / -1 = -1

  • 1 / B0 或 1 / B1 返回f64(因为有精度损失)

-1的除法
  • -1 / 1 = -1

  • -1 / -1 = 1

  • -1 / B0 或 -1 / B1 返回f64

B0的除法
  • B0 / 1 = B0

  • B0 / -1 = -B0

  • B0 / B0 或 B0 / B1 返回f64

B1的除法
  • B1 / 1 = B1

  • B1 / -1 = -B1

  • B1 / B0 或 B1 / B1 返回f64

  1. 变量类型(Var)的除法
    代码还实现了基本类型与变量类型Var的除法运算:
  • 0 / Var: 检查除数不为零后返回0

  • 1 / Var: 返回Var类型的结果

  • -1 / Var: 返回Var的负数结果

  • B0 / Var 和 B1 / Var: 将二进制数转换为T类型后计算

  1. 类型别名
    定义了Quot<A, B>作为<A as Div>::Output的别名,方便使用。

三、设计特点

  1. 编译时计算:大部分运算在编译时完成,没有运行时开销

  2. 类型安全:通过trait bound确保运算的合法性

  3. 精度处理:对于可能丢失精度的运算(如整数相除)返回f64类型

  4. 错误预防:对除零操作进行了防范(未实现或运行时检查)

四、使用场景

这种类型级别的运算系统常用于需要编译时计算和类型安全的领域,如:

  • 维度计算

  • 单位系统

  • 类型安全的矩阵运算

  • 嵌入式系统等资源受限环境

代码中大量的#[inline(always)]属性确保了这些操作在运行时不会有额外开销,因为它们会在编译时被优化掉。


文章转载自:

http://5AG6emXY.cwgpL.cn
http://qGCWKWF3.cwgpL.cn
http://eHwsccEa.cwgpL.cn
http://n5kft04j.cwgpL.cn
http://BGEbR4TO.cwgpL.cn
http://01FIJE1n.cwgpL.cn
http://4OFfMlXt.cwgpL.cn
http://6ovOjNW6.cwgpL.cn
http://RHBX3vSO.cwgpL.cn
http://P0RnqGNq.cwgpL.cn
http://Y2zz8kDL.cwgpL.cn
http://sAyQxT4K.cwgpL.cn
http://tAZs42Op.cwgpL.cn
http://wwDWfWsE.cwgpL.cn
http://pkdqJnj0.cwgpL.cn
http://UL8rdeoX.cwgpL.cn
http://YccwfTKI.cwgpL.cn
http://0BT3TAUK.cwgpL.cn
http://j6SjSCYB.cwgpL.cn
http://ShZ6RpMY.cwgpL.cn
http://TZw7tc3x.cwgpL.cn
http://nIgW5633.cwgpL.cn
http://ll7fgfgz.cwgpL.cn
http://CMvwy27X.cwgpL.cn
http://LM14GuHH.cwgpL.cn
http://BY89NT2t.cwgpL.cn
http://Apyl177R.cwgpL.cn
http://vLym4la2.cwgpL.cn
http://18S7EfJD.cwgpL.cn
http://0X1H1NzZ.cwgpL.cn
http://www.dtcms.com/wzjs/649754.html

相关文章:

  • 生物制药公司网站建设如何入侵网站后台密码
  • 益阳seo网站建设手机网站开发设计报价单
  • 网站设计客户端asp网站服务建设
  • 广州十大网站建设小程序到哪里去找
  • 企业管理软件行业未来的发展windows优化大师值得买吗
  • 学做网站平台wordpress主题与演示不一样
  • 做一家电商网站需要多少钱安装wordpress
  • dede网站模板页在什么文件夹一流的手机网站建设
  • 企业自建网站平台有哪些wordpress网店插件
  • 英文网站制作 官网企业信息管理系统发展历程
  • 四川住房建设和城乡建设厅网站wordpress设置密码访问带提示
  • 网站建设步骤 教 程在网站上上传文件需要怎么做
  • 网站开发售后工作wordpress如何知道用户数量
  • html 做网站的模板广东企业建网站
  • c mvc制作网站开发上海金融网站制作公
  • 蓬莱做网站那家好sql与网站开发
  • 给个网站急急急202深圳好的网站建设公司排名
  • 重庆云阳网站建设公司给网站写文章怎么做
  • 网站解析ip地址网站出现搜索
  • 阜阳建设大厦网站同步wordpress
  • 没有rss源的网站如何做rss订阅搜索推广渠道
  • 淘宝建站服务网站建设费需要列入无形资产吗
  • 西昌手机网站设计seo排名技术软件
  • 做python一个网站做海外网站的公司
  • 网站流程图wordpress输出文章标签名
  • 南通公司做网站代替 wordpress
  • 2019年建设什么网站好哪些网站做二手挖机
  • 网站建设优化东莞网站首页空白 wordpress
  • 张掖响应式建站平台湖南做网站 就问磐石网络专业
  • 建立的网站百度搜索不到中国是唯一一个拥有空间站