Sqrt function needs optimization advice -
I have a function set, which can calculate the square root of a number. I want a suggestion about optimization advice or speed, or improvement of this code. I code is given below:
Unsigned characters AcountDigits (int v) {unsigned RR = (V & gt; = 1000000000)? 9: (V> = 100000000)? 8: (V> = 10000000)? 7: (V> = 1000000)? 6: (V> = 100000)? 5: (V> = 10000)? 4: (V> = 1000)? 3: (V> = 100)? 2: (V> = 10)? 1: 0; Returns R + 1; Unsigned int ASqrt_LastDeduction (unsigned int x, unsigned int y) {unsigned int result = 10 * y; If (x <4 + 10 * y * 2) {result + = 1; } And if (x <9 + 10 * y * 3) {Results + = 3; } And if (x <16 + 10 * y * 4) {Results + = 5; } And if (x <25 + 10 * y * 5) {Results + = 7; } And if (x <36 + 10 * y * 6) {Results + = 9; } And if (x <50 + 10 * y * 7) {Results + = 11; } And if (x <64 + 10 * y * 8) {Results + = 13; } And if (x <81 + 10 * y * 9) {Results + = 15; } And if (x & lt; 100 + 10 * y * 10) {result + = 17; } Return results; } Unsigned four ASCart_remanners (unsigned four digits, four unsigned four, last fall, unsigned four years) {return number - (((final deduction + 1-10 * y) / 2) * ((final deduction + 1-10 * y) / 2) + 10 * y * (lastDeduction-10 * y + 1) / 2); } Double Ascert (Int. Whole, int decim) {int wdgcn = Accident Digits (complete); Int ddgcn = accentigits (dcim); Unsigned four wgrp [(int) (wdgcn / 2) + 1]; Unsigned four DNP [(Int) (DDGCN / 2) + 1]; Int i = 0; For (i = (int) (wdgcn / 2); i> = 0; i--) {wgrp [i] = whole% 100; Absolute / = 100; } For (i = 0; i & lt; = (ddgcn / 2); i ++) {DGRP [i] = decim% 100; Decim / = 100; Unsigned int lastDeduction = 0; Unsigned four deductible = 0; Unsigned int balance = 0; Unsigned int y = 0; Unsigned integer tempInt = wgrp [0]; Unsigned int wRoot = 0; For (i = 0; i & lt; = (wdgcn / 2); i ++) {final deduction = escort_last deduction (tempInt, y); Deduction = (final deduction + 1-10 * y) / 2; Balance = escort_armanner (tempInt, final cut, y); WRoot = wRoot * 10 + deductions; Y = final deduction + 1; TempInt = 100 * Balance + wgrp [i + 1]; } TempInt = 100 * Balance + DGRP [0]; Final cut = escort_listed deduction (temint, y); Deduction = (final deduction + 1-10 * y) / 2; Balance = escort_armanner (tempInt, final cut, y); Return (double) (WRUT + deduction / 10 + remaining / (final deduction + 1)); }
Thank you for any tips you provided. It helps a lot.
Comments
Post a Comment