### Revision history for KeyPgSqr

#### Revision [22291]

Last edited on 2018-04-25 02:56:44 by fxm [Changed SQR() as overloadable operator, but only from fbc version 1.06]##### Additions:

##**Sqr**## can be overloaded as operator to accept user-defined types (only from fbc version 1.06).

##### Deletions:

##### Additions:

##**Sqr**## cannot be overloaded as operator to accept user-defined types.

##### Additions:

If a ##[[KeyPgLongint|Longint]]## or ##[[KeyPgUlongint|ULongint]]## is passed to ##**Sqr**##, it may be converted to ##[[KeyPgDouble|Double]]## precision first. For numbers over ##2^52##, this will cause a very small loss of precision. Without making any assumptions about the rounding method, the maximum error due to this will be ##**Sqr**(2^64) - **Sqr**(2^64-2^12)##, which is about ##4.8e-7##. However this may cause erroneous results if the floor or ceiling of this value is taken, and the result of this may be out by ##1##, particularly for square numbers and numbers that are close by.

##### Deletions:

##### Additions:

##### Additions:

[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Sqr** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgDouble|double]] ) [[KeyPgAs|as]] [[KeyPgDouble|double]]

This is the same as raising the argument ##//number//## to the one-half power: ##//y// = //x// [[KeyPgOpExponentiate|^]] (1/2)## . The required ##//number//## argument can be any valid numeric expression greater than or equal zero.

If a ##[[KeyPglongint|Longint]]## or ##[[KeyPgUlongint|ULongint]]## is passed to ##**Sqr**##, it may be converted to ##[[KeyPgDouble|Double]]## precision first. For numbers over ##2^52##, this will cause a very small loss of precision. Without making any assumptions about the rounding method, the maximum error due to this will be ##**Sqr**(2^64) - **Sqr**(2^64-2^12)##, which is about ##4.8e-7##. However this may cause erroneous results if the floor or ceiling of this value is taken, and the result of this may be out by ##1##, particularly for square numbers and numbers that are close by.

- ##[[KeyPgOpExponentiate|Operator ^ (Exponentiate)]]##

- [[CatPgMath|Arithmetic Operators]]

This is the same as raising the argument ##//number//## to the one-half power: ##//y// = //x// [[KeyPgOpExponentiate|^]] (1/2)## . The required ##//number//## argument can be any valid numeric expression greater than or equal zero.

If a ##[[KeyPglongint|Longint]]## or ##[[KeyPgUlongint|ULongint]]## is passed to ##**Sqr**##, it may be converted to ##[[KeyPgDouble|Double]]## precision first. For numbers over ##2^52##, this will cause a very small loss of precision. Without making any assumptions about the rounding method, the maximum error due to this will be ##**Sqr**(2^64) - **Sqr**(2^64-2^12)##, which is about ##4.8e-7##. However this may cause erroneous results if the floor or ceiling of this value is taken, and the result of this may be out by ##1##, particularly for square numbers and numbers that are close by.

- ##[[KeyPgOpExponentiate|Operator ^ (Exponentiate)]]##

- [[CatPgMath|Arithmetic Operators]]

##### Deletions:

This is the same as raising the argument ##//number//## to the one-half power: ##//y// = //x// [[KeyPgOpExponentiate ^]] (1/2)## . The required ##//number//## argument can be any valid numeric expression greater than or equal zero.

If a ##[[KeyPglongint Longint]]## or ##[[KeyPgUlongint ULongint]]## is passed to ##**Sqr**##, it may be converted to ##[[KeyPgDouble Double]]## precision first. For numbers over ##2^52##, this will cause a very small loss of precision. Without making any assumptions about the rounding method, the maximum error due to this will be ##**Sqr**(2^64) - **Sqr**(2^64-2^12)##, which is about ##4.8e-7##. However this may cause erroneous results if the floor or ceiling of this value is taken, and the result of this may be out by ##1##, particularly for square numbers and numbers that are close by.

- ##[[KeyPgOpExponentiate Operator ^ (Exponentiate)]]##

- [[CatPgMath Arithmetic Operators]]

#### Revision [16343]

Edited on 2012-09-12 12:44:51 by CountingPine [In practice, there may actually be no loss of precision for 64-bit integers, depending on how the va]##### Additions:

If a ##[[KeyPglongint Longint]]## or ##[[KeyPgUlongint ULongint]]## is passed to ##**Sqr**##, it may be converted to ##[[KeyPgDouble Double]]## precision first. For numbers over ##2^52##, this will cause a very small loss of precision. Without making any assumptions about the rounding method, the maximum error due to this will be ##**Sqr**(2^64) - **Sqr**(2^64-2^12)##, which is about ##4.8e-7##. However this may cause erroneous results if the floor or ceiling of this value is taken, and the result of this may be out by ##1##, particularly for square numbers and numbers that are close by.

##### Deletions:

#### Revision [16342]

Edited on 2012-09-12 12:03:33 by CountingPine [Warning about 64-bit integer operand precision; minor example changes]##### Additions:

If a ##[[KeyPglongint Longint]]## or ##[[KeyPgUlongint ULongint]]## is passed to ##**Sqr**##, it will be converted to a ##[[KeyPgDouble Double]]## first. For numbers over ##2^52##, this will cause a very small loss of precision. Without making any assumptions about the rounding method, the maximum error due to this will be ##**Sqr**(2^64) - **Sqr**(2^64-2^12)##, which is about ##4.8e-7##. However this may cause erroneous results if the floor or ceiling of this value is taken, and the result of this may be out by ##1##, particularly for square numbers and numbers that are close by.

'' Example of Sqr function: Pythagorean theorem

Dim As Single a, b

Print "Pythagorean theorem, right-angled triangle"

Print

Input "Please enter one leg side length: ", a

Input "Please enter the other leg side length: ", b

Print

Print "The hypotenuse has a length of: " & Sqr( a * a + b * b )

Pythagorean theorem, right-angled triangle

Please enter one leg side length: 1.5

Please enter the other leg side length: 2

The hypotenuse has a length of: 2.5

'' Example of Sqr function: Pythagorean theorem

Dim As Single a, b

Print "Pythagorean theorem, right-angled triangle"

Input "Please enter one leg side length: ", a

Input "Please enter the other leg side length: ", b

Print "The hypotenuse has a length of: " & Sqr( a * a + b * b )

Pythagorean theorem, right-angled triangle

Please enter one leg side length: 1.5

Please enter the other leg side length: 2

The hypotenuse has a length of: 2.5

##### Deletions:

DIM AS SINGLE a , b

PRINT "Pythagorean theorem , right triangle"

INPUT "Please enter one leg side length: ", a

INPUT "Please enter the other leg side length: ", b

PRINT "The hypotenuse has a length of: " ; SQR ( a * a + b * b )

SLEEP

Pythagorean theorem , right triangle

Please enter one leg side length: 3

Please enter the other leg side length: 4

The hypotenuse has a length of: 5

##### Additions:

If ##//number//## equals zero, ##**Sqr**## returns zero (##0.0##).

If ##//number//## is less than zero, ##**Sqr**## returns a special value representing "not defined", printing like "##""NaN""##" or ##"IND"##, exact text is platform dependent.

This is the same as raising the argument ##//number//## to the one-half power: ##//y// = //x// [[KeyPgOpExponentiate ^]] (1/2)## . The required ##//number//## argument can be any valid numeric expression greater than or equal zero.

- ##[[KeyPgOpExponentiate Operator ^ (Exponentiate)]]##

If ##//number//## is less than zero, ##**Sqr**## returns a special value representing "not defined", printing like "##""NaN""##" or ##"IND"##, exact text is platform dependent.

This is the same as raising the argument ##//number//## to the one-half power: ##//y// = //x// [[KeyPgOpExponentiate ^]] (1/2)## . The required ##//number//## argument can be any valid numeric expression greater than or equal zero.

- ##[[KeyPgOpExponentiate Operator ^ (Exponentiate)]]##

##### Deletions:

If ##//number//## is less than zero, **Sqr** returns a special value representing "not defined", printing like """NaN""" or "IND", exact text is platform dependent.

This is the same as raising the argument //number// to the one-half power: y = x ^ (1/2) . The required ##//number//## argument can be any valid numeric expression greater than or equal zero.

No Differences

##### Additions:

result = **Sqr**( //number// )

##### Deletions:

##### Additions:

If ##//number//## is less than zero, **Sqr** returns a special value representing "not defined", printing like """NaN""" or "IND", exact text is platform dependent.

##### Deletions:

#### Revision [13804]

Edited on 2008-10-22 04:28:50 by DoS386 [minor, please recheck "domain error (-1.#IND)" [3]]##### Additions:

If ##//number//## is less than zero, **Sqr** returns a domain error (-1.#IND).

##### Deletions:

#### Revision [13799]

Edited on 2008-10-22 04:14:28 by DoS386 [minor, please recheck "domain error (-1.#IND)"]##### Additions:

PRINT "Pythagorean theorem , right triangle"

INPUT "Please enter one leg side length: ", a

INPUT "Please enter the other leg side length: ", b

Pythagorean theorem , right triangle

Please enter one leg side length: 3

Please enter the other leg side length: 4

INPUT "Please enter one leg side length: ", a

INPUT "Please enter the other leg side length: ", b

Pythagorean theorem , right triangle

Please enter one leg side length: 3

Please enter the other leg side length: 4

##### Deletions:

INPUT "Please enter one leg side: ", a

INPUT "Please enter the other leg side: ", b

Right triangle

Please enter one leg side: 3

Please enter the other leg side: 4

#### Revision [13796]

Edited on 2008-10-22 03:38:56 by DoS386 [minor, plese recheck "domain error (-1.#IND)"]##### Additions:

This is the same as raising the argument //number// to the one-half power: y = x ^ (1/2) . The required ##//number//## argument can be any valid numeric expression greater than or equal zero.

'' Example of sqr function: Pythagorean theorem

DIM AS SINGLE a , b

PRINT "Right triangle"

PRINT

INPUT "Please enter one leg side: ", a

INPUT "Please enter the other leg side: ", b

PRINT

PRINT "The hypotenuse has a length of: " ; SQR ( a * a + b * b )

Right triangle

Please enter one leg side: 3

Please enter the other leg side: 4

The hypotenuse has a length of: 5

'' Example of sqr function: Pythagorean theorem

DIM AS SINGLE a , b

PRINT "Right triangle"

INPUT "Please enter one leg side: ", a

INPUT "Please enter the other leg side: ", b

PRINT "The hypotenuse has a length of: " ; SQR ( a * a + b * b )

Right triangle

Please enter one leg side: 3

Please enter the other leg side: 4

The hypotenuse has a length of: 5

##### Deletions:

DIM a AS SINGLE

DIM b AS SINGLE

INPUT "Please enter one side of a right triangle: ",a

INPUT "Please enter another side of a right triangle: ",b

PRINT ""

PRINT "The hypotenuse of the triangle has a length of"; SQR ( a * a + b * b )

Please enter one side of a Right triangle: 3

Please enter another side of a Right triangle: 4

The hypotenuse of the triangle has a length of 5