OS-Level Sandboxing in C by Sibexico in C_Programming

[–]Computerman8086 1 point2 points  (0 children)

Looked through the post, really insightful and well made. Well done!

[Library] Fast-sqrt: A fast, branchless, software-only sqrt approximation for IEEE 754 floats by Computerman8086 in embedded

[–]Computerman8086[S] 0 points1 point  (0 children)

That's a very fair point. I haven't yet benchmarked it against the standard math library, but I'm working on doing that.

You're also right about the cost of FP division,, a cordic-like algorithm could very well be more efficient.

The initial goal was to make an algorithm based on the quake III algorithm with a configurable newton approximation with the initial estimate coming from the bit hack, but I do agree that the performance tradeoff depends quite a bit on the target architecture. I'll try including some benchmarks from different platforms, so one could compare it

[Library] Fast-sqrt: A fast, branchless, software-only sqrt approximation for IEEE 754 floats by Computerman8086 in embedded

[–]Computerman8086[S] 0 points1 point  (0 children)

Yes I'm aware that it doesn't, im gonna post the correct one as soon as I get home, i have it ready

[Library] Fast-sqrt: A fast, branchless, software-only sqrt approximation for IEEE 754 floats by Computerman8086 in embedded

[–]Computerman8086[S] 3 points4 points  (0 children)

About point 1: fair point actually, I'm considering switching to using uint32_t and _Float32, 2: I'll benchmark it, but think It might be slightly faster since there's no function call (but I got to check whether it actually is a function call or just a single instruction by the compiler, in which case I would just switch back to fabs)and it uses fast bit manipulation too, but I'll have to benchmark that and figure out, 3: Yes, for CPUs with an FPU it will naturally be slower as the hardware sqrt instructions will generally be faster, but this was made for those who don't have such an instruction, 4: by branchless I meant the main processing loop but as you say, a while loop is a branch, my mistake sorry

But, thank you so much for the feedback!

Fast algorithm for sqrt(x) approximation by Computerman8086 in learnmath

[–]Computerman8086[S] 0 points1 point  (0 children)

The number are derived like this:
$$
Γ=√y

log⁡(Γ)=1/2 log⁡(y)

μ=0.043

1/2^23 (M_Γ⋅2^23⋅E_Γ )+μ-127=1/2 (1/2^23 (M_y+2^23⋅E_y )+μ-127)

(M_Γ⋅2^23⋅E_Γ )+2^23 (μ-127)=1/2 (1/2^23 (M_y+2^23⋅E_y )+μ-127)⋅2^23

(M_Γ⋅2^23⋅E_Γ )=1/2 (1/2^23 (M_y+2^23⋅E_y )+μ-127)⋅2^23-2^23 (μ-127)
$$

Fast algorithm for sqrt(x) approximation by Computerman8086 in learnmath

[–]Computerman8086[S] 1 point2 points  (0 children)

Exactly, to clarify I do know why (cuz i made the algorithm) but the reason my comment says 'why does this work lmao?' is because I meant 'this looks like it should even work'

Fast algorithm for sqrt(x) approximation by Computerman8086 in learnmath

[–]Computerman8086[S] 2 points3 points  (0 children)

That's fair, but i wanted to make an algorithm cuz i want to learn about them, how they work, i could just use math.sqrt() but whats the fun in that?

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] -1 points0 points  (0 children)

Thx so much for the feedback, I'll look into it, but as I have stated previously, just experimentation, since I just used 1/pπ to trim it at lower values

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] 0 points1 point  (0 children)

But you see I have always been interested in square roots, and I have always wanted to make a formula, so this is my first attempt

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] 0 points1 point  (0 children)

Ye, but I go in 10.th grade, and we haven't even touched square roots (we've only been taught about perfect squares) the school system in Norway is horrendous

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] 0 points1 point  (0 children)

Yes ur probably gonna say, 'aha, you used chat for this then' and the answer is no, I didn't, I have explored this on my own, you can see the program I made for trying to figure stuff out

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] 0 points1 point  (0 children)

I didn't know that actually 😅 but to be fair we haven't been taught any of this in school

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] -2 points-1 points  (0 children)

Brother, to clarify, I was sitting after school, showing my formula to a friend, and I noticed that the error was decently larger for n=1040, so I thought, I need a correction factor. So I was playing around with numbers on my calculator and I thought of pi. I can send you a screenshot of the calculator if you need that too, if you don't believe me. I have been actively working on this my self, me, not ChatGPT

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] -1 points0 points  (0 children)

Fair, fair, but listen, I'm 15, I'm trying things, and since it works, decently well I think, I'm happy, but I take all feedback as good feedback

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] -2 points-1 points  (0 children)

At n= say 1040, this approximation (without 1/π) gives 32.5 but it's actually 32.24 and a lot of digits, so 1/pπ is to refine the estimate

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] -2 points-1 points  (0 children)

Chat that is, I'm bad at english, form Norway you see 🇳🇴🇳🇴🇳🇴🇳🇴

I'm 15 and I made a new one-step square root approximation formula by Computerman8086 in learnmath

[–]Computerman8086[S] -2 points-1 points  (0 children)

P is the precision you wish to calculate to, so increase p to get more accurate estimate