WEIGHTED_SUM(9)

✨ WEIGHTED_SUM ✨

okay bestie, so this is a page from the HAL Component section of the manual (section 9, kernel/component-land, iykyk) and it's literally about turning a lil group of bits into one big integer. it's giving "binary but make it customizable" πŸ’…


πŸŽ€ NAME πŸŽ€

weighted_sum β€” converts a group of bits into an integer. that's it, that's the whole job πŸ’–


🌸 SYNOPSIS 🌸

loadrt weighted_sum wsum_sizes=size[,size,...]

this makes weighted sum groups, and each one gets however many input bits you told it (that's the size). so if you pass a comma-separated list of sizes, you get one weighted summer per size. periodt ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so weighted_sum takes a group of bits and turns them into an integer, no cap. the conversion is the sum of the weights of all the bits that are on, plus any offset you've got hanging around.

the weight of the m-th bit is 2^m. it's kinda like a binary coded decimal but with way more options β€” main character energy honestly πŸ‘‘

and then there's the hold bit: it stops the processing of input changes, so the sum just… won't change. it's frozen. it's in its own little world 🌈

by default, each weight is 2^m where m is the bit number. that default combo gives you a binary to unsigned conversion, which is a vibe.

heads up bestie: there's a limit of 8 weighted summers, and each one can have up to 16 input bits. that's the ceiling, don't fight it 😭

🧚 FUNCTIONS 🧚

  • process_wsums (requires a floating point thread) β€” reads all the input values and updates all the output values. it's the little engine that could 🫢

πŸ’œ PINS πŸ’œ

  • wsum.N.bit.M.in bit in β€” the m-th input of weighted summer n. yes, N and M, very math, very slay.
  • wsum.N.hold bit in β€” when it's TRUE, the sum output does not change. when it's FALSE, the sum output tracks the bit inputs according to the weights and the offset. so TRUE = frozen, FALSE = doing the most πŸ”₯
  • wsum.N.sum signed out β€” the output of the weighted summer. the moment we've all been waiting for ⭐
  • wsum.N.bit.M.weight signed rw β€” the weight of the m-th input of weighted summer n. default value is 2^m, obviously πŸ’…
  • wsum.N.offset signed rw β€” this offset gets added to the weights of all the TRUE inputs to give you the final sum. it's the lil bonus on top πŸ“

πŸ‘‘ SEE ALSO πŸ‘‘

scaled_s32_sums(9), sum2(9). go read those next, bestie, they're also iconic πŸ’–


mwah, that's a wrap! this page came to you from the LinuxCNC Documentation, dated 2007-01-16, and it lives at WEIGHTED_SUM(9) in the HAL Component section. drink water, check your weights, and go convert some bits πŸŒΈβœ¨πŸŽ€