// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Solve a quadratic with reduced cancellation // Not compiled or tested in-world // Setup: Place in a spare owned prim. Set A/B/C for A*x*x+B*x+C=0. Touch to run; output is private to the owner. // Stop / restore: Disable/remove. No scene changes or external calls. // Notes: Handles linear equations, repeated roots and negative discriminants. Very large coefficients can still overflow float arithmetic. // License: see LICENSE in this distribution. // Original Incoprea. MIT. float A=1.0; float B=-100.0; float C=1.0; default { touch_start(integer detectedCount) { if(llDetectedKey(0)!=llGetOwner())return; if(llFabs(A)<0.000001) { if(llFabs(B)<0.000001) { llOwnerSay("No unique linear root."); return; } llOwnerSay("Linear root="+(string)(-C/B)); return; } float discriminant=B*B-4.0*A*C; if(discriminant<0.0) { llOwnerSay("No real roots."); return; } float root=llSqrt(discriminant); float signedRoot=root; if(B<0.0)signedRoot=-root; float q=-0.5*(B+signedRoot); if(llFabs(q)<0.000001) { llOwnerSay("Repeated root="+(string)(-B/(2.0*A))); return; } llOwnerSay("Roots="+(string)(q/A)+" and "+(string)(C/q)); } }