iPXE
Functions
isqrt.c File Reference

Integer square root. More...

#include <ipxe/isqrt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
unsigned long isqrt (unsigned long value)
 Find integer square root.

Detailed Description

Integer square root.

Definition in file isqrt.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
unsigned long isqrt ( unsigned long  value)

Find integer square root.

Parameters:
valueValue
isqrtInteger square root of value

Definition at line 40 of file isqrt.c.

Referenced by math_test_exec(), and profile_stddev().

                                            {
        unsigned long result = 0;
        unsigned long bit = ( 1UL << ( ( 8 * sizeof ( bit ) ) - 2 ) );

        while ( bit > value )
                bit >>= 2;
        while ( bit ) {
                if ( value >= ( result + bit ) ) {
                        value -= ( result + bit );
                        result = ( ( result >> 1 ) + bit );
                } else {
                        result >>= 1;
                }
                bit >>= 2;
        }
        return result;
}