1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-FileCopyrightText: 2026 John Moxley
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Typed-`W` Newton-root *seed* bridge over the cross-algorithm seed leaf.
//!
//! [`sqrt_seed_w`] hands a generic wide integer `W: BigInt` to the
//! `&[u64]`-based seed leaf ([`crate::algo_x_support::seed::sqrt_seed`])
//! and rebuilds the resulting seed back into `W`. It is the seed-only
//! companion of the floor-root surface `W::isqrt` (which produces the
//! *final* root): the wide fixed-point `sqrt` kernel in
//! [`decl_wide_transcendental!`](crate::macros::wide_transcendental) needs
//! the over-estimate *seed* to start its own scaled Newton loop, not the
//! integer floor root, so it cannot use `W::isqrt` directly.
//!
//! The leaf encapsulates the only `std`/`no_std` divergence: under `std`
//! it bootstraps from `f64::sqrt` of the top 64 significant bits of `n`
//! (~53 correct bits in one shot); under `no_std` it falls back to the
//! classical pure-integer 1-bit seed (`2^⌈bits/2⌉`) — pure-integer math,
//! never `libm` / `num_traits::Float`. Either way the seed is a safe
//! over-estimate, so the caller's monotone-downward Newton loop converges
//! to the same floor root.
//!
//! ## `W ↔ &[u64]` bridge
//!
//! The leaf is `&[u64]`-based; `W: BigInt` has an opaque `Limbs` type, so
//! the two are bridged through the kept u128 magnitude surface
//! ([`BigInt::mag_into_u128`] / [`BigInt::from_mag_sign_u128`]): the
//! operand's magnitude is unpacked into a `u64` work slice, fed to the
//! leaf, and the `u64` seed limbs are repacked into u128 limbs to rebuild
//! `W`. No `BigInt` method is added, and the leaf stays a pure `&[u64]`
//! leaf.
use cratesqrt_seed;
use crateComputeLimbs;
use crateBigInt;
/// Unpacks the magnitude of `n` into the `u64` work slice `out_u64`
/// (little-endian), returning the populated length. Bridges the kept
/// u128 magnitude surface ([`BigInt::mag_into_u128`]) to the seed leaf's
/// `&[u64]` interface — pure primitive limb splitting, no `BigInt`
/// method beyond the existing magnitude bridge.
/// Rebuilds a non-negative `W` from the little-endian `u64` seed limbs
/// `seed_u64`. The inverse of [`mag_to_u64`]: repacks pairs of `u64`
/// limbs into u128 limbs and hands them to the kept
/// [`BigInt::from_mag_sign_u128`] bridge.
/// Newton *seed* for `⌊√n⌋` in the wide integer `W`, sourced from the
/// cross-algorithm seed leaf ([`crate::algo_x_support::seed::sqrt_seed`]).
///
/// Bridges the leaf's `&[u64]` interface to generic `W` (see the module
/// docs): unpacks `n`'s magnitude to a `u64` work slice, calls the leaf,
/// repacks the `u64` seed limbs into `W`. The leaf chooses the `std` f64
/// bootstrap or the `no_std` 1-bit fallback internally; both are safe
/// over-estimates. Always returns `≥ W::ONE`.
pub