Skip to content

SY-4127: Divide F64 Typecast - Trade and RFC#2274

Open
sy-nico wants to merge 29 commits intorcfrom
sy-4127-arc-divide-f64-typecast-rfc-and-trade-study
Open

SY-4127: Divide F64 Typecast - Trade and RFC#2274
sy-nico wants to merge 29 commits intorcfrom
sy-4127-arc-divide-f64-typecast-rfc-and-trade-study

Conversation

@sy-nico
Copy link
Copy Markdown
Contributor

@sy-nico sy-nico commented Apr 28, 2026

Pull Request

SY-4127

Greptile Summary

This PR adds an RFC and a trade study documenting the decision to have Arc's / and ** operators always return f64 and to replace divide-by-zero panics with IEEE 754 special values (+Inf, -Inf, NaN). The documents are comprehensive and well-reasoned, covering type-system arguments, precision trade-offs, migration guidance, and a full change-footprint breakdown.

Confidence Score: 5/5

Documentation-only PR; safe to merge with the minor example-clarity nit addressed.

Both files are documentation (RFC + trade study); no production code is changed. The single finding is a P2 style issue in a code example. No logic bugs or security concerns.

docs/tech/rfc/0038-260425-division-power-f64-typecast.md — §3.2 code examples

Important Files Changed

Filename Overview
docs/tech/rfc/0038-260425-division-power-f64-typecast.md RFC specifying division/power always return f64, with IEEE 754 divide-by-zero semantics; two identical code examples in §3.2 reduce readability of the key NaN vs +Inf contrast.
docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md Trade study evaluating Option A (f64 output) vs Option B (preserve input type); well-structured with criterion-by-criterion analysis and a clear recommendation for Option A.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Arc expression: a / b  or  a ** b"] --> B{Operator}
    B -->|"/  or  **"| C["Analyzer: force result type → f64"]
    B -->|"+ − × %"| D["Return input type (no change)"]
    C --> E{Execution context}
    E -->|Flow node| F["divide{} / pow{} host function\n(T, T) → f64"]
    E -->|WASM func block| G["Compiler emits call to\nmath.divide / math.pow host fn"]
    F --> H{Denominator = 0?}
    G --> H
    H -->|"n/0, n≠0"| I["+Inf or -Inf (truthy)"]
    H -->|"0/0"| J["NaN (non-truthy)"]
    H -->|normal| L["f64 result"]
    I --> M[isSeriesTruthy check]
    J --> M
    L --> M
Loading

Reviews (3): Last reviewed commit: "SY-4127: Update docs based on feedback/d..." | Re-trigger Greptile

sy-nico added 27 commits April 14, 2026 18:57
* Add ExecContext gates: analyzer rejects WASM-only nodes in flow statements, compiler rejects flow-only nodes in func blocks, LSP filters completions by execution context
* Add flow representation for `time.now` (C++ and Go), making it the first ExecBoth node
* Add optional `offset` parameter to `time.now` for both WASM and flow execution paths
* Support negated literals in flow config values (e.g. `offset=-3h`)
* Unit and integration tests across all layers
* Gate exec context at call sites rather than the resolver, because resolver gating conflates wrong-context with undefined, requiring extra error plumbing to distinguish them and to avoid passing `ResolveAny` to 22 unrelated interfaces
…g in CompoundFactory

Add status.set() as the preferred qualified form for set_status, with deprecation warning, LSP hover docs, and tests across Go and C++.

Fix a latent bug in CompoundFactory/MultiFactory where qualified names with the same member (e.g. authority.set vs status.set) would collide after prefix stripping. Factories can now declare a module name so the dispatcher routes to the correct one.
…upport

Move add, subtract, multiply, divide, mod, neg from op into math with deprecation warnings for bare forms. Symbols are ExecBoth, callable in both func blocks and flow statements. WASM host bindings added across all numeric types in Go and C++. pow remains ExecWASM only.

Consolidate shared code for integration tests and hover.go
…s.set routing

- Add SignedNumericConstraint kind that promotes unsigned types to wider signed equivalents (u8→i16, u16→i32, u32→i64, u64→f64) for math.neg
- Add cross-type negate ops (NegateU8/U16/U32/U64) in telem/op
- Handle promotion in both WASM compiler and flow constraint unifier
- Fix CompoundFactory routing: move ModuleName() to Module so status nodes don't intercept authority.set
- Restore status.set name config parameter
- Check exec context before argument validation in analyzer
…improve error messages, and validate now() offset type
…since both are now internal. The `len` hover doc remains. The compiler dispatch for `string.len` stays since it's used internally when `len()` dispatches based on argument type.
@sy-nico sy-nico requested review from emilbon99 and pjdotson April 28, 2026 03:53
Comment thread docs/tech/rfc/0038-260425-division-power-f64-typecast.md Outdated
Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
@sy-nico sy-nico force-pushed the sy-4127-arc-divide-f64-typecast-rfc-and-trade-study branch from a6f4512 to 877685e Compare April 28, 2026 04:14
Copy link
Copy Markdown
Contributor

@pjdotson pjdotson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left comments here, but we should be mostly having discussions about this in-person, I just wanted to put extra things to think about. I also think that the error / exception handling is something that needs to be discussed as well: what does returning errors for functions look like in both the flow and func contexts (this is something that also is encountered with ranges + statuses RFC and it really does not feel like we have a consistent story on that, and instead are just doing things slapshot as they arise).

Comment thread docs/tech/rfc/0038-260425-division-power-f64-typecast.md Outdated
Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
Comment thread docs/tech/rfc/0038-260425-division-power-f64-typecast.md Outdated
Comment thread docs/tech/rfc/0038-260425-division-power-f64-typecast.md Outdated
Comment thread docs/tech/rfc/0038-260425-division-power-f64-typecast.md Outdated
Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md Outdated
@sy-nico
Copy link
Copy Markdown
Contributor Author

sy-nico commented Apr 29, 2026

@pjdotson , replying to your top-level comment.

  • Agreed, but it was time to put the concerns on paper since the discussion was starting to go in circles. I needed your thoughts/concerns/objections in a way that I could address point by point. Something that gets hard to do in-person the longer the conversation drags on.
  • Also agreed that error/exception handling needs to be discussed, but not here. Typecasting division to f64 cleanly sidesteps this conversation to the contexts where errors/statuses actually make sense (metadata CRUD, etc.), rather than math operations.
  • If we went with Option B, error handling would absolutely need to be part of this RFC. That's another reason Option A is the cleaner choice: it removes the error-handling question from the math layer entirely and lets us tackle it in the contexts where it actually belongs, rather than shoe-horn error handling and create more avenues for inconsistency, which backs us into a corner.

@sy-nico sy-nico requested a review from pjdotson April 29, 2026 01:48
Base automatically changed from sy-4071-dot-module-syntax-followup to rc April 30, 2026 02:01
- **Strictly typed**: Every value has a definite type known at compile time, and the
compiler enforces type rules at every boundary.
- **Strongly typed**: No implicit coercion between unrelated types. The programmer must
explicitly convert (e.g., JavaScript's `"5" + 3 = "53"` is weak typing).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where you are getting these definitions of strongly vs strictly. From what
I've read before about typing in languages, there is a general strong typing vs weak
typing axis, along with static typing vs dynamic typing and nominal vs structual. But I
haven't heard and can't really seem to find a difference between strict and strong

Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
returns its input type. `+`, `-`, `*`, `%` stay in the integer domain because they
produce exact integer results from integer inputs. `/` and `**` do not, so they return
`f64`. The rule is in the math (like derivative), not in matching the input datatype,
which ignores what the operators actually do.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below, but it feels like that the sections: type system consistency,
precision errors, and consistency with other operations are mostly reiterating the same
point. There should be one section called user expectation that goes for option A
because most current users expect it to return a float, and another section for
mathematical operator type consistency that goes with option B because when we perform
these primitive math operators (/, %, +, etc.) that are binary operators on two
objects of the same type, the output is the same type as the inputs.


The counterargument is that low-level hardware engineers expect C-style integer
division. Every customer we have spoken to disagrees. They come from Python, LabVIEW, or
MATLAB, where division returns floats.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be the same argument as some of the above sections as well

Comment thread docs/tech/rfc/0038-260425-divide-typecast-f64-trade-study.md
| Divide by zero | ✓ | |
| Language identity | ✓ | |
| Reliability | ✓ | |
| Safety | ✓ | |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add a section explicitly stating that error / exception behavior would need to be
added here as well for option B.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants