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

动态网站的发展趋势百度百科推广费用

动态网站的发展趋势,百度百科推广费用,兰州网站建设哪家专业,网易企业邮箱满了怎么办一、源码 这段代码定义了一个类型级(type-level)的数字系统,用于在编译时表示和处理数字。它使用了Rust的类型系统和泛型编程来实现。 use core::marker::PhantomData; use crate::sealed::Sealed;// Special floating-point values #[derive(Debug, PartialEq, D…

一、源码

这段代码定义了一个类型级(type-level)的数字系统,用于在编译时表示和处理数字。它使用了Rust的类型系统和泛型编程来实现。

use core::marker::PhantomData;
use crate::sealed::Sealed;// Special floating-point values
#[derive(Debug, PartialEq, Default)]
pub enum Special {#[default]Nan,        // Not a NumberInfinity,   // Positive infinityNegInfinity,// Negative infinity
}// Basic numeric type representations/// Terminal representation for decimal 0
/// - Atomic constant in type system
/// - Cannot be used as generic parameter for B0/B1
#[derive(Eq, PartialEq, Clone, Copy, Debug, Default)]
pub struct Z0;/// Positive sign terminator / numeric 1 representation
/// - Standalone: value 1
/// - As generic parameter: 
///   - Current bit is 1
///   - Higher bits are 0
///   - Example: B1<P1> represents 011 (+3)
#[derive(Eq, PartialEq, Clone, Copy, Debug, Default)]
pub struct P1;/// Negative sign terminator / numeric -1 representation
/// - Standalone: value -1
/// - As generic parameter:
///   - Current bit is 1
///   - Higher bits are 1
///   - Example: B0<N1> represents ...1110 (-2)
#[derive(Eq, PartialEq, Clone, Copy, Debug, Default)]
pub struct N1;/// Binary digit 0 for two's complement
/// - H: Higher bits
/// - Example: B0<P1> represents 010 (+2)
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub struct B0<H>(PhantomData<H>);impl<H> Default for B0<H> {fn default() -> Self { B0(PhantomData) }
}/// Binary digit 1 for two's complement
/// - H: Higher bits
/// - Example: B1<P1> represents 011 (+3)
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub struct B1<H>(PhantomData<H>);impl<H> Default for B1<H> {fn default() -> Self { B1(PhantomData) }
}/// Floating-point number in type-level scientific notation (M × 2^E)
/// - Mantissa: Significand (includes sign)
/// - Exponent: In two's complement
/// - Supports NaN, +∞, -∞
#[derive(Clone, Copy, Debug)]
pub struct Float<Mantissa, Exponent>(PhantomData<(Mantissa, Exponent)>);impl<Mantissa, Exponent> Default for Float<Mantissa, Exponent> {fn default() -> Self { Float(PhantomData) }
}/// Bridge between library types and primitive numeric types
/// - Enables mixed operations between custom and primitive types
/// - Provides type-safe operator overloading
/// - Example: Var(3) + P1 → i32 + type-level 1
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Var<T>(pub T);// Constructors
impl Z0 { #[inline] pub fn new() -> Self { Z0 } }
impl P1 { #[inline] pub fn new() -> Self { P1 } }
impl N1 { #[inline] pub fn new() -> Self { N1 } }impl<H> B0<H> { #[inline] pub fn new() -> Self { B0(PhantomData) } 
}impl<H> B1<H> { #[inline] pub fn new() -> Self { B1(PhantomData) } 
}impl<Mantissa, Exponent> Float<Mantissa, Exponent> {#[inline] pub fn new() -> Self { Float(PhantomData) }
}// Sealed trait implementations
impl Sealed for Special {}
impl Sealed for Z0 {}
impl Sealed for P1 {}
impl Sealed for N1 {}
impl<H> Sealed for B0<H> {}
impl<H> Sealed for B1<H> {}
impl<Mantissa, Exponent> Sealed for Float<Mantissa, Exponent> {}
impl Sealed for Var<i8> {}
impl Sealed for Var<i16> {}
impl Sealed for Var<i32> {}
impl Sealed for Var<i64> {}
impl Sealed for Var<i128> {}
impl Sealed for Var<isize> {}
impl Sealed for Var<f32> {}
impl Sealed for Var<f64> {}

二、代码分析

  1. 特殊浮点值 (Special 枚举)
pub enum Special {#[default]Nan,        // 非数字Infinity,   // 正无穷NegInfinity,// 负无穷
}

表示浮点数中的特殊值:NaN(非数字)、正无穷和负无穷。

  1. 基本数字类型表示
Z0
pub struct Z0;

表示十进制数字0的终止符,是类型系统中的原子常量。

P1 和 N1
pub struct P1;  // 正1
pub struct N1;  // 负1
  • P1:表示正1,也可以作为正号的终止符

  • N1:表示负1,也可以作为负号的终止符

  1. 二进制数字表示 (用于补码)
B0 和 B1
pub struct B0<H>(PhantomData<H>);  // 二进制0
pub struct B1<H>(PhantomData<H>);  // 二进制1

使用泛型表示二进制数字:

  • B0 表示二进制0

  • B1 表示二进制1

  • H 是更高位的类型参数

使用 PhantomData 来保持类型参数但不占用实际存储空间

  1. 浮点数表示 (Float)
pub struct Float<Mantissa, Exponent>(PhantomData<(Mantissa, Exponent)>);

用类型级科学计数法表示浮点数:

  • Mantissa:尾数/有效数字(包含符号)

  • Exponent:指数(用补码表示)

  • 支持特殊值(NaN, ±∞)

  1. 桥梁类型 (Var)
pub struct Var<T>(pub T);

在库类型和原始数值类型之间建立桥梁:

+允许自定义类型和原始类型之间的混合操作

+提供类型安全的运算符重载

+例如:Var(3) + P1 表示 i32 + 类型级1

  1. 构造函数
    为所有类型提供了简单的构造函数(new()),使用PhantomData来构造泛型类型。

  2. Sealed trait 实现

impl Sealed for Special {}
// ...其他类型的实现...

实现了Sealed trait,这是一种设计模式,用于限制哪些类型可以实现特定的trait,防止外部类型实现这些trait。

三、设计特点:

  • 类型级编程:使用Rust的类型系统在编译时表示和处理数字

  • 零运行时开销:所有信息都在类型中表示,运行时没有额外开销

  • 安全抽象:通过Sealed trait限制实现,保证类型安全

  • 灵活扩展:可以表示整数、浮点数及其各种运算

这种设计常见于需要编译时计算或验证的领域,如物理单位系统、金融计算等,可以在编译时捕获更多的错误。

http://www.dtcms.com/wzjs/159338.html

相关文章:

  • 做app要不要建网站最新舆情信息网
  • 专做畜牧招聘网站的网站运营策划书范文
  • 图片无版权网站厦门网站流量优化价格
  • 网站营销站点有你想seo案例分享
  • 如何推广个人网站深圳seo优化公司排名
  • flash网站设计教程网络营销服务企业有哪些
  • 朋友给我做网站深圳网络营销推广渠道
  • 东莞专业微网站建设镇江关键字优化公司
  • javaweb网站首页怎么做南宁关键词优化软件
  • 深圳石岩做网站的公司济南计算机培训机构哪个最好
  • 做交友网站年收入模板网站建设开发
  • 济南做外贸的网站公司自有品牌如何推广
  • 做音乐头像网站宁波正规站内优化seo
  • 知识付费商城源码深圳专业seo
  • 网站框架图成都调查事务所
  • 管理网站开发教程管理人员课程培训
  • 日照建网站公司专业培训大全
  • wikidot怎么建设网站怎么创建个人网站
  • 台州制作网站软件石家庄谷歌seo
  • android开发环境有哪些技术教程优化搜索引擎整站
  • 做网站较好的公司商业网站设计
  • 怎么看网站是哪里做的网络营销过程步骤
  • 创意视差wordpress主题怎样做seo搜索引擎优化
  • 云南省网站建设2024年最新一轮阳性症状
  • 做搜狗网站点击赚钱怎么设计网站
  • 深圳网站建设怎样网络推广网站公司
  • 番禺网站制作 优帮云google play三件套
  • 新闻类网站怎么做百度推广电商如何推广自己的产品
  • oa管理系统软件搜索引擎优化解释
  • 用php做视频网站有哪些百度人工在线客服