Intop-SquareRoot

Computes the square root of an integer number.

Summary
Intop-SquareRootComputes the square root of an integer number.
CopyrightThis program is free software.
Files
C-kern/api/math/int/sqroot.hHeader file Intop-SquareRoot.
C-kern/math/int/sqroot.cImplementation file Intop-SquareRoot impl.
Functions
test
unittest_math_int_sqrootTests implementation of sqroot_int.
int_t
compute
sqroot_intReturns the square root of an unsigned integer number.
sqroot_int32Returns the square root from an unsigned 32 bit integer.
sqroot_int64Returns the square root from an unsigned 64 bit integer.
inline implementation
Functions
sqroot_intImplements int_t.sqroot_int.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2012 Jörg Seebohn

Files

C-kern/api/math/int/sqroot.h

Header file Intop-SquareRoot.

C-kern/math/int/sqroot.c

Implementation file Intop-SquareRoot impl.

Functions

Summary

test

unittest_math_int_sqroot

int unittest_math_int_sqroot(void)

Tests implementation of sqroot_int.

int_t

Summary
compute
sqroot_intReturns the square root of an unsigned integer number.
sqroot_int32Returns the square root from an unsigned 32 bit integer.
sqroot_int64Returns the square root from an unsigned 64 bit integer.

compute

sqroot_int

unsigned sqroot_int(unsigned number)

Returns the square root of an unsigned integer number.  This function is generic in that it accepts either 32 or 64 bit unsigned integers and selects the corresponding implementation.  The returned value has the following property:

number >= sqroot_int(number) * sqroot_int(number)
&& number < (sqroot_int(number)+1) * (sqroot_int(number)+1)

sqroot_int32

uint16_t sqroot_int32(uint32_t number)

Returns the square root from an unsigned 32 bit integer.  This function is called from sqroot_int.

sqroot_int64

uint32_t sqroot_int64(uint64_t number)

Returns the square root from an unsigned 64 bit integer.  This function is called from sqroot_int.

inline implementation

Functions

sqroot_int

Implements int_t.sqroot_int.  Calls sys_sqroot_int64 for a faster implementation of the default implementation sqroot_int64.  TODO: reimplement it with _Generic

Computes the square root of an integer number.
Implements Intop-SquareRoot.
int unittest_math_int_sqroot(void)
Tests implementation of sqroot_int.
Implements int_t.sqroot_int.
unsigned sqroot_int(unsigned number)
Returns the square root of an unsigned integer number.
uint16_t sqroot_int32(uint32_t number)
Returns the square root from an unsigned 32 bit integer.
uint32_t sqroot_int64(uint64_t number)
Returns the square root from an unsigned 64 bit integer.
#define sys_sqroot_int64 sqrtl
Replaces sqroot_int64 with faster sqrtl (long double version).
uint32_t sqroot_int64(uint64_t number)
Implements the High School Square Root Algorithm for 64 bit unsigned integer.
Close