How to compulse X raised to n?

this is an example that I tried

but is not correct

finit

fldz

fld TailleQW ; ex: 175 = X

fld S0725QW ;ex : 0.725= n

call XtoN

fst TailleQW

;=============================================

; Computes X to the Nth power. |

;=============================================

XtoN proc

fxch

fld1

fxch

fyl2x

fmul

call TwoX

ret

XtoN endp

;============================================

; Computes 2 to the Nth power. |

;===========================================

TwoX PROC

fldcw CWNoRound

fld st(0) ; Duplicate tos.

fld st(0)

frndint ; Compute integer portion.

fxch ; Swap whole and int values.

fsub st(0), st(1) ; Compute fractional part.

f2xm1 ; Compute 2**frac(x)-1.

fld1 ; Load 1

fadd ; Compute 2**frac(x).

fxch ; Get integer portion.

fld1 ; Compute 1*2**int(x).

fscale

fstp st(1) ; Remove st(1) (which is 1).

fmul ; Compute 2**int(x) * 2**frac(x).

fldcw CWRound ; Restore rounding mode.

RET

TwoX ENDP

this is an example that I tried

but is not correct

finit

fldz

fld TailleQW ; ex: 175 = X

fld S0725QW ;ex : 0.725= n

call XtoN

fst TailleQW

;=============================================

; Computes X to the Nth power. |

;=============================================

XtoN proc

fxch

fld1

fxch

fyl2x

fmul

call TwoX

ret

XtoN endp

;============================================

; Computes 2 to the Nth power. |

;===========================================

TwoX PROC

fldcw CWNoRound

fld st(0) ; Duplicate tos.

fld st(0)

frndint ; Compute integer portion.

fxch ; Swap whole and int values.

fsub st(0), st(1) ; Compute fractional part.

f2xm1 ; Compute 2**frac(x)-1.

fld1 ; Load 1

fadd ; Compute 2**frac(x).

fxch ; Get integer portion.

fld1 ; Compute 1*2**int(x).

fscale

fstp st(1) ; Remove st(1) (which is 1).

fmul ; Compute 2**int(x) * 2**frac(x).

fldcw CWRound ; Restore rounding mode.

RET

TwoX ENDP

You're theory is definitly correct. You do need to break up the power into an integer and a bit between -1.0 to 1.0. So the problem is probably something small.

Anyway here's a MACRO I wrote which will do what you want, it does exactly what you were trying to do. Note there was no need to ensure your code rounded down, the range for non integer number cover negative to -1.0.

XtY Macro ;Raise X to Y, st(1) = st(0)^st(1), st(0) popped

fyl2x

fld st

frndint

fsub st(1),st

fld1

fscale

fxch

fstp st

fxch

f2xm1

fld1

fadd

fmul

EndM

Usage is as follows

.data

X dq 5.6

Y dq 4.5

.code

fld Y

fld X

XtY

; st(0) now equals 2327.2665

Anyway here's a MACRO I wrote which will do what you want, it does exactly what you were trying to do. Note there was no need to ensure your code rounded down, the range for non integer number cover negative to -1.0.

XtY Macro ;Raise X to Y, st(1) = st(0)^st(1), st(0) popped

fyl2x

fld st

frndint

fsub st(1),st

fld1

fscale

fxch

fstp st

fxch

f2xm1

fld1

fadd

fmul

EndM

Usage is as follows

.data

X dq 5.6

Y dq 4.5

.code

fld Y

fld X

XtY

; st(0) now equals 2327.2665

There is an impressive online book that

Check it out, I think its a real assest...

NaN

**rafe**posted a while ago at this link... Its mainly C but the idea is what is important to know. It talks about how to handle mathematical equantions in the land of finite precision :)Check it out, I think its a real assest...

NaN