Skip to content

Commit

Permalink
add float const value
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Jun 29, 2023
1 parent 9bc5cbb commit bc57f97
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ops/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum ConstValue {
value: HugrIntValueStore,
width: HugrIntWidthStore,
},
/// Double precision float
F64(f64),
/// A constant specifying a variant of a Sum type.
Sum {
tag: usize,
Expand Down Expand Up @@ -90,6 +92,8 @@ impl PartialEq for ConstValue {
) => tag == t1 && variants == type1 && val == v1,

(Self::Tuple(v1), Self::Tuple(v2)) => v1.eq(v2),
(Self::F64(f1), Self::F64(f2)) => f1 == f2,

_ => false,
}
}
Expand Down Expand Up @@ -122,12 +126,14 @@ impl ConstValue {
.collect();
ClassicType::Container(Container::Tuple(Box::new(row.into())))
}
Self::F64(_) => ClassicType::F64,
}
}
/// Unique name of the constant.
pub fn name(&self) -> SmolStr {
match self {
Self::Int { value, width } => format!("const:int<{width}>:{value}"),
Self::F64(f) => format!("const:float:{f}"),
Self::Opaque(_, v) => format!("const:{}", v.name()),
Self::Sum { tag, val, .. } => {
format!("const:sum:{{tag:{tag}, val:{}}}", val.name())
Expand Down

0 comments on commit bc57f97

Please sign in to comment.