# ajmath.c

#### FunctionajRound

Rounds an integer to be a multiple of a given number.

#### Synopsis

##### Prototype
```ajint ajRound (
ajint i,
ajint vround
);
```

ajintiInputInteger to round.
ajintvroundInputRounding multiple.
ajint RETURNResult.

##### Input
 i: (Input) Integer to round. vround: (Input) Rounding multiple.
##### Returns
 ajint: Result.

#### Description

Rounds an integer to be a multiple of a given number.

See other functions in this section

In release 6.4.0

#### FunctionajRoundFloat

Rounds a floating point number to have bits free for cumulative addition

#### Synopsis

##### Prototype
```float ajRoundFloat (
float a,
ajint nbits
);
```

floataInputFloat to round.
ajintnbitsInputNumber of bits to free.
float RETURNResult.

##### Input
 a: (Input) Float to round. nbits: (Input) Number of bits to free.
##### Returns
 float: Result.

#### Description

Rounds a floating point number to have bits free for cumulative addition

See other functions in this section

In release 6.4.0

#### FunctionajCvtRecToPol

Converts Cartesian coordinates to polar

#### Synopsis

##### Prototype
```void ajCvtRecToPol (
float x,
float y,
float* angle
);
```

floatxInputX coordinate
floatyInputY coordinate
float*angleOutputAngle
void RETURN

##### Input
 x: (Input) X coordinate y: (Input) Y coordinate
##### Returns
 void: No return value

#### Description

Converts Cartesian coordinates to polar

See other functions in this section

In release 6.4.0

#### FunctionajCvtPolToRec

Converts polar coordinates to Cartesian

#### Synopsis

##### Prototype
```void ajCvtPolToRec (
float angle,
float* x,
float* y
);
```

floatangleInputAngle
float*xOutputX coordinate
float*yOutputY coordinate
void RETURN

##### Output
 x: (Output) X coordinate y: (Output) Y coordinate
##### Returns
 void: No return value

#### Description

Converts polar coordinates to Cartesian

See other functions in this section

In release 6.4.0

#### Synopsis

##### Prototype
```float ajCvtDegToRad (
float degrees
);
```

floatdegreesInputDegrees

##### Input
 degrees: (Input) Degrees

#### Description

See other functions in this section

In release 6.4.0

#### Synopsis

##### Prototype
```float ajCvtRadToDeg (
);
```

float RETURNDegrees

##### Returns
 float: Degrees

#### Description

See other functions in this section

In release 6.4.0

#### FunctionajCvtGaussToProb

Returns a probability given a Gaussian distribution

#### Synopsis

##### Prototype
```double ajCvtGaussToProb (
float mean,
float sd,
float score
);
```

floatmeanInputmean
floatsdInputsd
floatscoreInputscore
double RETURNprobability

##### Input
 mean: (Input) mean sd: (Input) sd score: (Input) score
##### Returns
 double: probability

#### Description

Returns a probability given a Gaussian distribution

See other functions in this section

In release 6.4.0

#### FunctionajMathGmean

Calculate a geometric mean

#### Synopsis

##### Prototype
```float ajMathGmean (
const float* s,
ajint n
);
```

const float*sInputarray of values
ajintnInputnumber of values
float RETURNgeometric mean

##### Input
 s: (Input) array of values n: (Input) number of values
##### Returns
 float: geometric mean

#### Description

Calculate a geometric mean

See other functions in this section

In release 6.4.0

#### FunctionajMathModulo

Modulo always returning positive number

#### Synopsis

##### Prototype
```ajint ajMathModulo (
ajint a,
ajint b
);
```

ajintaInputvalue1
ajintbInputvalue2
ajint RETURNvalue1 modulo value2

##### Input
 a: (Input) value1 b: (Input) value2
##### Returns
 ajint: value1 modulo value2

#### Description

Modulo always returning positive number

See other functions in this section

In release 6.4.0

#### FunctionajRandomSeed

Seed for the ajRandomDouble routine

Based on dprand and sdprand and used with the permission of the author.... Copyright (C) 1992 N.M. Maclaren Copyright (C) 1992 The University of Cambridge

This software may be reproduced and used freely, provided that all users of it agree that the copyright holders are not liable for any damage or injury caused by use of this software and that this condition is passed onto all subsequent recipients of the software, whether modified or not.

#### Synopsis

##### Prototype
```void ajRandomSeed (
void
);
```

void RETURN

##### Returns
 void: No return value

#### Description

Seed for the ajRandomDouble routine

Based on dprand and sdprand and used with the permission of the author.... Copyright (C) 1992 N.M. Maclaren Copyright (C) 1992 The University of Cambridge

This software may be reproduced and used freely, provided that all users of it agree that the copyright holders are not liable for any damage or injury caused by use of this software and that this condition is passed onto all subsequent recipients of the software, whether modified or not.

See other functions in this section

In release 6.4.0

#### FunctionajRandomNumber

Generate a pseudo-random number between 0-32767

#### Synopsis

##### Prototype
```ajint ajRandomNumber (
void
);
```

ajint RETURNRandom number

##### Returns
 ajint: Random number

#### Description

Generate a pseudo-random number between 0-32767

See other functions in this section

In release 6.4.0

#### FunctionajRandomDouble

Generate a random number between 0-1.0

Based on dprand and sdprand and used with the permission of the author.... Copyright (C) 1992 N.M. Maclaren Copyright (C) 1992 The University of Cambridge

This software may be reproduced and used freely, provided that all users of it agree that the copyright holders are not liable for any damage or injury caused by use of this software and that this condition is passed onto all subsequent recipients of the software, whether modified or not.

#### Synopsis

##### Prototype
```double ajRandomDouble (
void
);
```

double RETURNRandom number

##### Returns
 double: Random number

#### Description

Generate a random number between 0-1.0

Based on dprand and sdprand and used with the permission of the author.... Copyright (C) 1992 N.M. Maclaren Copyright (C) 1992 The University of Cambridge

This software may be reproduced and used freely, provided that all users of it agree that the copyright holders are not liable for any damage or injury caused by use of this software and that this condition is passed onto all subsequent recipients of the software, whether modified or not.

See other functions in this section

In release 6.4.0

#### FunctionajMathCrc32

Calculates the SwissProt style CRC32 checksum for a protein sequence. This seems to be a bit reversal of a standard CRC32 checksum.

#### Synopsis

##### Prototype
```ajuint ajMathCrc32 (
const AjPStr seq
);
```

const AjPStrseqInputSequence as a string
ajuint RETURNCRC32 checksum.

##### Input
 seq: (Input) Sequence as a string
##### Returns
 ajuint: CRC32 checksum.

#### Description

Calculates the SwissProt style CRC32 checksum for a protein sequence. This seems to be a bit reversal of a standard CRC32 checksum.

See other functions in this section

In release 6.4.0

#### FunctionajMathCrc64

Calculate 64-bit crc

#### Synopsis

##### Prototype
```unsigned long long ajMathCrc64 (
const AjPStr thys
);
```

const AjPStrthysInputsequence
unsigned long long RETURN64-bit CRC

##### Input
 thys: (Input) sequence
##### Returns
 unsigned long long: 64-bit CRC

#### Description

Calculate 64-bit crc

See other functions in this section

In release 6.4.0

#### FunctionajCvtSposToPos

Converts a string position into a true position. If ipos is negative, it is counted from the end of the string rather than the beginning.

#### Synopsis

##### Prototype
```size_t ajCvtSposToPos (
size_t len,
ajlong ipos
);
```

size_tlenInputString length.
ajlongiposInputPosition (0 start, negative from the end).
size_t RETURNstring position between 0 and (length minus 1).

##### Input
 len: (Input) String length. ipos: (Input) Position (0 start, negative from the end).
##### Returns
 size_t: string position between 0 and (length minus 1).

#### Description

Converts a string position into a true position. If ipos is negative, it is counted from the end of the string rather than the beginning.

See other functions in this section

In release 6.4.0

#### FunctionajCvtSposToPosStart

Converts a position into a true position. If ipos is negative, it is counted from the end of the string rather than the beginning.

imin is a minimum relative position. Usually this is the start position when the end of a range is being tested.

#### Synopsis

##### Prototype
```size_t ajCvtSposToPosStart (
size_t len,
size_t imin,
ajlong ipos
);
```

size_tlenInputmaximum length.
size_timinInputStart position (0 start, no negative values).
ajlongiposInputPosition (0 start, negative from the end).
size_t RETURNstring position between 0 and (length minus 1).

##### Input
 len: (Input) maximum length. imin: (Input) Start position (0 start, no negative values). ipos: (Input) Position (0 start, negative from the end).
##### Returns
 size_t: string position between 0 and (length minus 1).

#### Description

Converts a position into a true position. If ipos is negative, it is counted from the end of the string rather than the beginning.

imin is a minimum relative position. Usually this is the start position when the end of a range is being tested.

See other functions in this section

In release 6.4.0

#### FunctionajNumLengthDouble

Returns the length of a number written as an integer

#### Synopsis

##### Prototype
```ajuint ajNumLengthDouble (
double dnumber
);
```

doublednumberInputDouble precision value
ajuint RETURNNumber of digits

##### Input
 dnumber: (Input) Double precision value
##### Returns
 ajuint: Number of digits

#### Description

Returns the length of a number written as an integer

See other functions in this section

In release 6.4.0

#### FunctionajNumLengthFloat

Returns the length of a number written as an integer

#### Synopsis

##### Prototype
```ajuint ajNumLengthFloat (
float fnumber
);
```

floatfnumberInputSingle precision value
ajuint RETURNNumber of digits

##### Input
 fnumber: (Input) Single precision value
##### Returns
 ajuint: Number of digits

#### Description

Returns the length of a number written as an integer

See other functions in this section

In release 6.4.0

#### FunctionajNumLengthInt

Returns the length of a number written as an integer

#### Synopsis

##### Prototype
```ajuint ajNumLengthInt (
ajlong inumber
);
```

ajlonginumberInputInteger
ajuint RETURNNumber of digits

##### Input
 inumber: (Input) Integer
##### Returns
 ajuint: Number of digits

#### Description

Returns the length of a number written as an integer

See other functions in this section

In release 6.4.0

#### FunctionajNumLengthUint

Returns the length of a number written as an integer

#### Synopsis

##### Prototype
```ajuint ajNumLengthUint (
ajulong inumber
);
```

ajulonginumberInputUnsigned integer
ajuint RETURNNumber of digits

##### Input
 inumber: (Input) Unsigned integer
##### Returns
 ajuint: Number of digits

#### Description

Returns the length of a number written as an integer

See other functions in this section

In release 6.4.0