Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ISO,IEC 10967-3 standard.Language independent arithmetic

.pdf
Скачиваний:
29
Добавлен:
23.08.2013
Размер:
453.11 Кб
Скачать

Working draft

ISO/IEC WD 10967-3.1:2001(E)

addc(I);i(I)(x +^ y;^ w)

= addI (x; rei(I)(^ w)) +^ addI (y; w)

addc(I) : c(I) c(I) ! c(I) [ fover owg

addc(I)(x +^ y; z +^ w)

= addI (x; z) +^ addI (y; w)

subi(I) : i(I) i(I) ! i(I) [ fover owg subi(I)(^ y;^ w)

= ^ subI (y; w)

 

subI;i(I) : I i(I) ! c(I) [ fover owg

 

subI;i(I)(x;^ w)

if x 2 I

= x +^ negI (w)

subi(I);I : i(I) I ! c(I) [ fover owg

 

subi(I);I (^ y; z)

if y 2 I

= negI (y) +^ y

subI;c(I) : I c(I) ! c(I) [ fover owg

subI;c(I)(x; z +^ w)

= subI (x; z) +^ subI (imI (x); w)

subc(I);I : c(I) I ! c(I) [ fover owg

subc(I);I (x +^ y; z)

= subI (x; z) +^ subI (y; imI (y))

subi(I);c(I) : i(I) c(I) ! c(I) [ fover owg

subi(I);c(I)(^ y; z +^ w)

= subI (rei(I)(^ y); z) +^ subI (y; w)

subc(I);i(I) : c(I) i(I) ! c(I) [ fover owg

subc(I);i(I)(x +^ y;^ w)

= subI (x; rei(I)(^ w)) +^ subI (y; w)

subc(I) : c(I) c(I) ! c(I) [ fover owg

subc(I)(x +^ y; z +^ w)

= subI (x; z) +^ subI (y; w)

muli(I) : i(I) i(I) ! I [ fover owg

 

muli(I)(^ y;^ w)

if y; w 2 I

= resultI ( (y w))

5.1.2 Imaginary and complex integer operations

13

ISO/IEC WD 10967-3.1:2001(E)

Working draft

mulI;i(I) : I i(I) ! i(I) [ fover owg

mulI;i(I)(x;^ w)

= ^ mulI (x; w)

muli(I);I : i(I) I ! i(I) [ fover owg

muli(I);I (^ y; z)

= ^ mulI (y; z)

mulI;c(I) : I c(I) ! c(I) [ fover owg

mulI;c(I)(x; z +^ w)

= mulI (x; z) +^ mulI (x; w)

mulc(I);I : c(I) I ! c(I) [ fover owg

mulc(I);I (x +^ y; z)

= mulI (x; z) +^ mulI (y; z)

muli(I);c(I) : i(I) c(I) ! c(I) [ fover owg

muli(I);c(I)(^ y; z +^ w)

= resultI ( y w) +^ resultI (y z) if y; z; w 2 I

mulc(I);i(I) : c(I) i(I) ! c(I) [ fover owg

mulc(I);i(I)(x +^ y;^ w)

= resultI ( y w) +^ resultI (x w) if x; y; w 2 I

mulc(I) : c(I) c(I) ! c(I) [ fover owg

mulc(I)(x +^ y; z +^ w)

= resultc(I)((x +~ y) (y +~ w))

if x; y; z; w 2 I

eqi(I) : i(I) i(I) ! Boolean

 

eqi(I)(x; z)

= true

if x; z 2 i(I) and x = z

 

= false

if x; z 2 i(I) and x 6= z

eqc(I) : c(I) c(I) ! Boolean

 

eqc(I)(x; z)

= true

if x; z 2 c(I) and x = z

 

= false

if x; z 2 c(I) and x 6= z

neqi(I) : i(I) i(I) ! Boolean

14

Speci cations for imaginary and complex datatypes and operations

Working draft

 

ISO/IEC WD 10967-3.1:2001(E)

neqi(I)(x; z)

= true

if x; z 2 i(I) and x 6= z

 

= false

if x; z 2 i(I) and x = z

neqc(I) : c(I) c(I) ! Boolean

 

neqc(I)(x; z)

= true

if x; z 2 c(I) and x 6= z

 

= false

if x; z 2 c(I) and x = z

5.2Imaginary and complex oating point datatypes and operations

Clause 5.2 of part 1 and clause 5.2 of part 2 specify oating point datatypes and a number of operations on values of a oating point datatype. In this clause complex oating point datatypes and operations on values of a complex oating point datatype are speci ed.

NOTE { Further operations on values of a complex oating point datatype, for elementary complex oating point numerical functions, are speci ed in clause 5.3.

F is the non-special value set, F R, for a oating point datatype conforming to part 1. Floating point datatypes conforming to part 1 often do contain 0, in nity, and NaN values.

Therefore, in this clause there are speci cations for such values as arguments.

i(F ) (see clause 4.1.5) is the set of non-special values in an imaginary oating point datatype, constructed from the oating point datatype corresponding to the non-special value set F .

c(F ) (see clause 4.1.5) is the set of non-special values in a complex oating point datatype, constructed from the oating point datatype corresponding to the non-special value set F .

5.2.1The complex oating point result helper functions

resultc(F ) : C (R ! F ) ! c(F ) [ funder ow; over owg

resultc(F )(z; rnd)

= resultF (Re(z); rnd) +^ resultF (Im(z); rnd)

EDITOR'S NOTE { over ow and under ow can both occur 'simultaneously'

EDITOR'S NOTE { In C, the notion of accuracy is implementation de ned

NOTE 1 { resultF is de ned in part 2.

De ne the no resultc(F ), no result2c(F ), [....] helper functions: no resultc(F ) : c(F ) ! finvalidg

no resultc(F )(x +^ y)

= invalid(qNaN +^ qNaN)

if x; y 2 F [ f1; 0; +1g

= qNaN +^ qNaN if at least one of x and y is a quiet NaN and neither is a signalling NaN

= invalid(qNaN +^ qNaN)

if at least one of x or y is a signalling NaN

5.2 Imaginary and complex oating point datatypes and operations

15

ISO/IEC WD 10967-3.1:2001(E)

Working draft

no

 

resulti(F )(^ y)

if y 2 F [ f1; 0; +1g

 

 

 

= invalid(^ qNaN)

 

 

= ^ qNaN

if y is a quiet NaN

 

 

= invalid(^ qNaN)

if y is a signalling NaN

no resultF !c(F )(x)

= no resultc(F )(x +^ ?imF (x))

no resulti(F )!c(F )(^ x0)

= no resultc(F )(?rei(F )(x) +^ y)

no result2c(F ) : c(F ) c(F ) ! finvalidg

no result2c(F )(x +^ y; z +^ w)

= invalid(qNaN +^ qNaN)

if x; y; z; w 2 F [ f1; 0; +1g

= qNaN +^ qNaN if at least one of x, y, z, or w is a signalling NaN and neither is a signalling NaN

= invalid(qNaN +^ qNaN)

if at least one of x, y, z, or w is a signalling NaN

These helper functions are used to specify both NaN argument handling and to handle non-NaN- argument cases where invalid(qNaN +^ qNaN) is the appropriate result.

NOTE 2 { The handling of other special values, if available, is left unspeci ed by this part.

5.2.2Basic arithmetic for complex oating point

itimesF !i(F ) : F ! i(F )

if x 2 F [ f1; 0; +1g

itimesF !i(F )(x) = ^ x

 

= no

 

resulti(F )(^ x)

otherwise

 

 

itimesi(F )!F : i(F ) ! F [ f 0g

 

itimesi(F )!F (^ y)

 

 

= negF (y)

 

itimesc(F ) : c(F ) ! c(F [ f 0g)

 

itimesc(F )(x +^ y)

if x 2 F [ f1; 0; +1g

 

= negF (y) +^ x

reF : F ! F

= no

 

resultc(F )(x +^ y)

otherwise

 

 

 

 

if x 2 F [ f1; 0; +1g

reF (x)

= x

 

= no

 

resultF (x)

otherwise

 

 

rei(F ) : i(F ) ! f 0; 0g

16

Speci cations for imaginary and complex datatypes and operations

Working draft

ISO/IEC WD 10967-3.1:2001(E)

rei(F )(^ y)

= 0

if (y 2 F and x > 0) or y = +1

 

= 0

 

 

if (y 2 F and x < 0) or y 2 f1; 0g

 

= no

 

resultF (y)

otherwise

 

 

rec(F ) : c(F ) ! F

 

rec(F )(x +^ y) = x

if x 2 F [ f1; 0; +1g

 

= no

 

resultF (x)

otherwise

 

 

imF : F ! f 0; 0g

if (x 2 F and x > 0) or x = +1

imF (x)

= 0

 

= 0

 

 

if (x 2 F and x < 0) or x 2 f1; 0g

 

= no

 

resultF (x)

otherwise

 

 

imi(F ) : i(F ) ! F

 

imi(F )(^ y)

= y

if y 2 F [ f1; 0; +1g

 

= no

 

resultF (y)

otherwise

 

 

imc(F ) : c(F ) ! F

 

imc(F )(x +^ y)

= y

if y 2 F [ f1; 0; +1g

 

 

= no

 

resultF (y)

otherwise

 

 

plusitimesc(F ) : F F ! c(F )

 

plusitimesc(F )(x; z)

if x; z 2 F [ f1; 0; +1g

 

= x +^ z

 

= no

 

resultc(F )(x +^ z)

otherwise

 

 

negi(F ) : i(F ) ! i(F [ f 0g)

 

negi(F )(^ y)

= ^ negF (y)

 

negc(F ) : c(F ) ! c(F [ f 0g)

negc(F )(x +^ y)

= negF (x) +^ negF (y)

conj conj

conj conj

conj

F : F ! F

 

 

 

if x 2 F [ f1; 0; +1g

F (x)

= x

 

= no

 

resultF (x)

otherwise

 

 

i(F ) : i(F ) ! i(F [ f 0)g i(F )(^ y) = ^ negF (y)

c(F ) : c(F ) ! c(F [ f 0g)

5.2.2 Basic arithmetic for complex oating point

17

ISO/IEC WD 10967-3.1:2001(E)

Working draft

conj c(F )(x +^ y)

if x 2 F [ f1; 0; +1g

= x +^ negF (y)

= no

 

resultc(F )(x +^ y)

otherwise

 

addi(F ) : i(F ) i(F ) ! i(F ) [ f(under ow); over owg

addi(F )(^ y;^ w)

= ^ addF (y; w)

addF;i(F ) : F i(F ) ! c(F )

 

addF;i(F )(x;^ w)

if x; w 2 F [ f1; 0; +1g

= x +^ w

= no

 

resultc(F )(x +^ w)

otherwise

 

addi(F );F : i(F ) F ! c(F )

 

addi(F );F (^ y; z)

if y; z 2 F [ f1; 0; +1g

= z +^ y

= no

 

resultc(F )(y +^ y)

otherwise

 

addF;c(F ) : F c(F ) ! c(F ) [ f(under ow); over owg

addF;c(F )(x; z +^ w)

= addF (x; z) +^ addF (imF (x); w)

addc(F );F : c(F ) F ! c(F ) [ f(under ow); over owg

addc(F );F (x +^ y; z)

= addF (x; z) +^ addF (y; imF (y))

addi(F );c(F ) : i(F ) c(F ) ! c(F ) [ f(under ow); over owg

addi(F );c(F )(^ y; z +^ w)

= addF (rei(F )(^ y); z) +^ addF (y; w)

addc(F );i(F ) : c(F ) i(F ) ! c(F ) [ f(under ow); over owg

addc(F );i(F )(x +^ y;^ w)

= addF (x; rei(F )(^ w)) +^ addF (y; w)

addc(F ) : c(F ) c(F ) ! c(F ) [ f(under ow); over owg

addc(F )(x +^ y; z +^ w)

= addF (x; y) +^ addF (y; w)

subi(F ) : i(F ) i(F ) ! i(F ) [ f(under ow); over owg

subi(F )(^ y;^ w)

= ^ subF (y; w)

18

Speci cations for imaginary and complex datatypes and operations

Working draft

ISO/IEC WD 10967-3.1:2001(E)

subF;i(F ) : F i(F ) ! c(F )

 

subF;i(F )(x;^ w)

if x 2 F [ f1; 0; +1g

= x +^ negF (w)

= no

 

resultc(F )(x +^ w)

otherwise

 

subi(F );F : i(F ) F ! c(F )

 

subi(F );F (^ y; z)

if y 2 F [ f1; 0; +1g

= negF (y) +^ y

= no

 

resultc(F )(y +^ y)

otherwise

 

subF;c(F ) : F c(F ) ! c(F ) [ f(under ow); over owg

subF;c(F )(x; z +^ w)

= subF (x; z) +^ subF (imF (x); w)

subc(F );F : c(F ) F ! c(F ) [ f(under ow); over owg

subc(F );F (x +^ y; z)

= subF (x; z) +^ subF (y; imF (y))

subi(F );c(F ) : i(F ) c(F ) ! c(F ) [ f(under ow); over owg

subi(F );c(F )(^ y; z +^ w)

= subF (rei(F )(y); z) +^ subF (y; w)

subc(F );i(F ) : c(F ) i(F ) ! c(F ) [ f(under ow); over owg

subc(F );i(F )(x +^ y;^ w)

= subF (x; rei(F )(w)) +^ subF (y; w)

subc(F ) : c(F ) c(F ) ! c(F ) [ f(under ow); over owg subc(F )(x; z) = addc(F )(x; negc(F )(y))

muli(F ) : i(F ) i(F ) ! F [ f 0; under ow; over owg

muli(F )(^ x;^ y)

= negF (mulF (x; y))

mulF;i(F ) : F i(F ) ! i(F [ f 0g) [ funder ow; over owg

mulF;i(F )(x;^ w)

= ^ mulF (x; w)

muli(F );F : i(F ) F ! i(F [ f 0g) [ funder ow; over owg

muli(F );F (^ y; z)

= ^ mulF (y; z)

5.2.2 Basic arithmetic for complex oating point

19

ISO/IEC WD 10967-3.1:2001(E)

Working draft

mulF;c(F ) : F c(F ) ! c(F [ f 0g) [ funder ow; over owg

mulF;c(F )(x; z +^ w)

= mulF (x; z) +^ mulF (x; w)

mulc(F );F : c(F ) F ! c(F [ f 0g) [ funder ow; over owg

mulc(F );F (x +^ y; z)

= mulF (x; z) +^ mulF (y; z)

muli(F );c(F ) : i(F ) c(F ) ! c(F [ f 0g) [ funder ow; over owg

muli(F );c(F )(^ y;^ w)

= negF (mulF (y; w)) +^ mulF (y; z)

mulc(F );i(F ) : c(F ) i(F ) ! c(F [ f 0g) [ funder ow; over owg

mulc(F );i(F )(^ y;^ w)

= negF (mulF (y; w)) +^ mulF (x; w)

NOTE 1 { mulc(F ) is speci ed in clause 5.2.3

divi(F ) : i(F ) i(F [ f 0g) ! F [ funder ow; over ow; in nitary; invalidg

divi(F )(^ x;^ y)

= divF (x; y)

divF;i(F ) : F i(F ) ! i(F [ f 0g) [ funder ow; over ow; in nitary; invalidg

divF;i(F )(x;^ w)

= ^ negF (divF (x; w))

divi(F );F : i(F ) F ! i(F [ f 0g) [ funder ow; over ow; in nitary; invalidg

divi(F );F (^ y; z)

= ^ divF (y; z)

divF;c(F ) : F c(F ) ! c(F [ f 0g) [ funder ow; over ow; in nitary; invalidg

divF;c(F )(x; z +^ w)

= divc(F )(x +^ imF (x); z +^ w)

divc(F );F : c(F ) F ! c(F [ f 0g) [ funder ow; over ow; in nitary; invalidg

divc(F );F (x +^ y; z)

= divF (x; z) +^ divF (y; z)

divi(F );c(F ) : i(F ) c(F ) ! c(F [ f 0g) [ funder ow; over ow; in nitary; invalidg

divi(F );c(F )(^ y; z +^ w)

= divc(F )(x +^ imF (x); z +^ w)

20

Speci cations for imaginary and complex datatypes and operations

signi(F )
absi(F )

Working draft

ISO/IEC WD 10967-3.1:2001(E)

divc(F );i(F ) : c(F ) i(F ) ! c(F [ f 0g) [ funder ow; over ow; in nitary; invalidg

divc(F );i(F )(x +^ y;^ w)

= divF (y; w) +^ negF (divF (x; y))

NOTE 2 {

divc(F ) is speci ed in clause 5.2.3

eqi(F ) : i(F ) i(F ) ! Boolean

eqi(F )(x; z)

= eqF (imi(F )(x); imi(F )(z))

eqc(F ) : c(F ) c(F ) ! Boolean

eqc(F )(x; z) = eqF (rec(F )(x); rec(F )(z)) and eqF (imc(F )(x); imc(F )(z))

neqi(F ) : i(F ) i(F ) ! Boolean

neqi(F )(x; z) = neqF (imi(F )(x); imi(F )(z))

neqc(F ) : c(F ) c(F ) ! Boolean

neqc(F )(x; z) = neqF (rec(F )(x); rec(F )(z)) or neqF (imc(F )(x); imc(F )(z))

: i(F ) ! F

absi(F )(^ y) = absF (y)

absc(F ) : c(F ) ! F [ funder ow; over owg

absc(F )(x +^ y)

= hypotF (x; y)

phaseF : F ! F

phaseF (x) = arcF (x; imF (x))

phasei(F ) : i(F ) ! F

phasei(F )(^ y) = arcF (rei(F )(^ y); y)

phasec(F ) : c(F ) ! F [ funder owg

phasec(F )(x +^ y)

= arcF (x; y)

: i(F ) ! i(F )

signi(F )(^ y) = ^ signF (y)

NOTE 3 { signc(F ) is speci ed in 5.2.3.

5.2.2 Basic arithmetic for complex oating point

21

ISO/IEC WD 10967-3.1:2001(E)

Working draft

5.2.3Complex multiplication, division, and sign

EDITOR'S NOTE { no sign requirements? no monotonicity requirements?

 

 

There shall be two maximum error parameters for complex multiplication and division.

 

 

 

max

 

error

 

mulc(F ) 2 F

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

max

 

error

 

divc(F ) 2 F

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The mulc(F ) approximation helper function:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mul

:

C C ! C

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c(F )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mul

 

(x; z) returns a close approximation to x

 

z in

C

with maximum error max

 

error

 

mul

c(F )

.

c(F )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Further requirement on the mulc(F ) approximation helper function are:

 

 

 

mulc(F )(z; z0) = mulc(F )(z0; z)

 

 

if z; z0

2 C

 

 

 

 

 

 

 

 

mul

(

 

z; z0) =

 

mul

(z; z0)

 

 

if z; z0

2 C

 

 

 

 

 

 

 

 

 

c(F )

 

 

 

 

c(F )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mulc(F )(conj(z); conj(z0)) = conj(mulc(F )(z; z0))

 

2 C

 

 

 

 

 

 

 

The mulc(F ) operation:

 

 

 

 

if z; z0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mulc(F ) : c(F ) c(F ) ! c(F [ f 0g) [ funder ow; over owg

 

 

 

mulc(F )(x +^ y; z +^ w)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

= result

 

(mul

(x +~

 

y; z +~

 

w))

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c(F )

 

c(F )

 

 

 

 

 

 

 

 

 

 

 

 

if x +^ y; z +^ w 2 c(F ) and x +~ y 6= 0 and y +~ w 6= 0

= subF (mulF (x; z); mulF (y; w)) +^ addF (mulF (x; w); mulF (y; z)) otherwise

EDITOR'S NOTE { -0...in nities...

NOTE 1 { invalid is not avoided in the \otherwise" case here. Note in particular cases like mulc(F )(2+^ ( 0); 3+^ (+1)) which is invalid with a continuation value of qNaN+^ qNaN (or qNaN +^ (+1)?). However, mulF;c(F )(2; 3 +^ (+1)) returns 6 +^ (+1).

The divc(F ) approximation helper function:

 

div

:

C C ! C

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c(F )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

div

 

(x; z) returns a close approximation to x=y in

C

with maximum error max

 

error

 

div

c(F )

.

c(F )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Further requirement on the divc(F ) approximation helper function are:

 

 

 

div

(

 

z; z0) =

 

div

(z; z0)

 

if z; z0

2 C

and z0

= 0

 

 

 

 

 

 

 

 

c(F )

 

 

 

c(F )

 

 

 

 

 

 

 

6

 

 

 

 

 

 

 

div

(z;

 

z0) =

 

div

(z; z0)

 

if z; z0

2 C

and z0

= 0

 

 

 

 

 

 

 

 

c(F )

 

 

 

 

c(F )

 

 

 

 

 

 

 

6

 

 

 

 

 

 

 

divc(F )(conj(z); conj(z0)) = conj(divc(F )(z; z0))

 

 

 

 

and z0

= 0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

if z; z0

2 C

 

 

 

 

 

 

The divc(F ) operation:

 

 

 

 

 

 

 

6

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

divc(F ) : c(F ) c(F ) ! c(F [ f 0g) [ funder ow; over ow; in nitary; invalidg

 

 

 

divc(F )(x +^ y; z +^ w)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

= result

(div

(x +~

 

y; z +~

 

w))

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c(F )

c(F )

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

if x +^ y; z +^ w 2 c(F ) and y +~ w 6= 0

 

 

 

 

 

 

 

 

 

= in nitary(:::)

 

if x +~ y 6= 0 and y +~ w 6= 0...?

 

 

 

 

 

 

 

 

 

 

=???

 

 

 

if ...

 

 

 

 

 

 

 

 

 

 

 

 

22

Speci cations for imaginary and complex datatypes and operations