Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d199db0
POC: scientific notation
Joshix-1 Jul 18, 2026
8770e6d
only insert . if precision > 1
Joshix-1 Jul 18, 2026
8c053e3
cargo fmt
Joshix-1 Jul 18, 2026
2003649
remove the redundant `&`
Joshix-1 Jul 18, 2026
8d2934f
bug fixes
Joshix-1 Jul 18, 2026
c38e127
rounding test, comment out failing test
Joshix-1 Jul 18, 2026
160604b
fix "pi to 4 sn"
Joshix-1 Jul 18, 2026
c35a190
try fix imaginary scientific notation
Joshix-1 Jul 18, 2026
7810334
fix rounding of integers with sf
Joshix-1 Jul 19, 2026
2664239
Merge branch 'fix-sf-rounding' into scientific-notation-poc
Joshix-1 Jul 19, 2026
f8b5d46
fix ci
Joshix-1 Jul 19, 2026
81914b7
uncommend rounding test and add another
Joshix-1 Jul 19, 2026
b2cfe40
always store base in FormattedBigUint
Joshix-1 Jul 19, 2026
81b953a
remove redundant bool option
Joshix-1 Jul 19, 2026
3c07135
add test_format_big_uint_hex
Joshix-1 Jul 19, 2026
cf659a5
fix ci
Joshix-1 Jul 19, 2026
5043350
test rounding base 9 and hex better
Joshix-1 Jul 19, 2026
7f8e606
Merge branch 'fix-sf-rounding' into scientific-notation-poc
Joshix-1 Jul 19, 2026
80e79a1
try to fix scientific notation with different bases
Joshix-1 Jul 19, 2026
8036d33
Merge branch 'fix-sf-rounding' into scientific-notation-poc
Joshix-1 Jul 19, 2026
8aba4da
remove manual logic from parse_char function
Joshix-1 Jul 19, 2026
8e2eae1
Merge branch 'fix-sf-rounding' into scientific-notation-poc
Joshix-1 Jul 19, 2026
be7a6d9
fix some bugs
Joshix-1 Jul 19, 2026
bca4e3a
add parentheses
Joshix-1 Jul 19, 2026
16effe1
fix bug with rounding 0.99 to 1
Joshix-1 Jul 19, 2026
3391c84
more tests
Joshix-1 Jul 19, 2026
95d5032
add carry logic
Joshix-1 Jul 19, 2026
07680a1
fix imaginary bug
Joshix-1 Jul 19, 2026
4589cf4
add base prefix
Joshix-1 Jul 19, 2026
4158002
fix bug with bases where i is a digit
Joshix-1 Jul 19, 2026
f75bca8
add tests from 390 pr
Safari77 Jul 19, 2026
8518c2e
more test cases
Joshix-1 Jul 20, 2026
c46b72e
more test cases
Joshix-1 Jul 20, 2026
e5c8e74
Merge branch 'fix-sf-rounding' into scientific-notation-poc
Joshix-1 Jul 20, 2026
cafbde9
add failing test
Joshix-1 Jul 20, 2026
47fb696
fix tests
Joshix-1 Jul 20, 2026
41bdaf6
Merge remote-tracking branch 'origin/main' into scientific-notation-poc
Joshix-1 Jul 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ fn evaluate_as<I: Interrupt>(
Value::Sf => {
return Err(FendError::SpecifyNumSf);
}
Value::Sn => {
return Err(FendError::SpecifyNumSn);
}
Value::Base(base) => Value::Num(Box::new(
evaluate(a, scope, attrs, spans, context, int)?
.expect_num()?
Expand Down Expand Up @@ -765,6 +768,7 @@ pub(crate) fn resolve_identifier<I: Interrupt>(
lowercase_builtin_result.or(unit_result)
}

#[allow(clippy::too_many_lines)]
fn resolve_builtin_identifier<I: Interrupt>(
ident: &Ident,
scope: Option<Arc<Scope>>,
Expand Down Expand Up @@ -847,6 +851,7 @@ fn resolve_builtin_identifier<I: Interrupt>(
"float" => Value::Format(FormattingStyle::ExactFloat),
"dp" => Value::Dp,
"sf" => Value::Sf,
"sn" => Value::Sn,
"base" => Value::BuiltInFunction(BuiltInFunction::Base),
"dec" | "decimal" => Value::Base(Base::from_plain_base(10)?),
"hex" | "hexadecimal" => Value::Base(Base::from_plain_base(16)?),
Expand Down
11 changes: 11 additions & 0 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ pub(crate) enum FendError {
InvalidDiceSyntax,
SpecifyNumDp,
SpecifyNumSf,
SpecifyNumSn,
UnableToInvertFunction(&'static str),
InvalidOperandsForSubtraction,
InversesOfLambdasUnsupported,
CouldNotFindKeyInObject,
CouldNotFindKey(String),
CannotFormatWithZeroSf,
CannotFormatWithZeroSn,
UnableToGetCurrentDate,
IsNotAFunction(String),
IsNotAFunctionOrNumber(String),
Expand Down Expand Up @@ -150,6 +152,9 @@ impl fmt::Display for FendError {
f,
"you need to specify what number of significant figures to use, e.g. '10 sf'"
),
Self::SpecifyNumSn => {
write!(f, "you need to specify what precision to use, e.g. '10 sn'")
}
Self::ExpectedAUnitlessNumber => write!(f, "expected a unitless number"),
Self::ExpectedARealNumber => write!(f, "expected a real number"),
Self::StringCannotBeLonger => write!(f, "string cannot be longer than one codepoint"),
Expand Down Expand Up @@ -189,6 +194,12 @@ impl fmt::Display for FendError {
Self::CannotFormatWithZeroSf => {
write!(f, "cannot format a number with zero significant figures")
}
Self::CannotFormatWithZeroSn => {
write!(
f,
"cannot format a number with zero precision in scientific notation"
)
}
Self::IsNotAFunction(s) => write!(f, "'{s}' is not a function"),
Self::IsNotAFunctionOrNumber(s) => write!(f, "'{s}' is not a function or number"),
Self::IdentifierNotFound(s) => write!(f, "unknown identifier '{s}'"),
Expand Down
18 changes: 17 additions & 1 deletion core/src/num/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ enum BaseEnum {

impl Base {
pub(crate) const HEX: Self = Self(BaseEnum::Hex);
#[cfg(test)]
pub(crate) const OCT: Self = Self(BaseEnum::Octal);
#[cfg(test)]
pub(crate) const BIN: Self = Self(BaseEnum::Binary);

pub(crate) const fn is_plain(self) -> bool {
matches!(self.0, BaseEnum::Plain(_))
}

pub(crate) const fn base_as_u8(self) -> u8 {
match self.0 {
Expand All @@ -35,6 +43,14 @@ impl Base {
}
}

pub(crate) const fn max_value(self) -> u8 {
self.base_as_u8() - 1
}

pub(crate) const fn max_char(self) -> char {
Self::digit_as_char(self.max_value() as _).expect("Max value is valid")
}

pub(crate) const fn from_zero_based_prefix_char(ch: char) -> FResult<Self> {
Ok(match ch {
'x' => Self(BaseEnum::Hex),
Expand Down Expand Up @@ -62,7 +78,7 @@ impl Base {
Ok(Self(BaseEnum::Custom(base)))
}

pub(crate) fn write_prefix(self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
pub(crate) fn write_prefix(self, f: &mut impl fmt::Write) -> Result<(), fmt::Error> {
match self.0 {
BaseEnum::Binary => write!(f, "0b")?,
BaseEnum::Octal => write!(f, "0o")?,
Expand Down
Loading
Loading