News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Normalizing two numbers.

Started by lucho, April 11, 2005, 12:35:17 PM

Previous topic - Next topic

lucho

Good Morning.

Well I have done this on decimal but I dont know how to do it on binary.

If I want to multiply 4 float numbers they must me normalizazed for example:

1.21 x 10E3 is different than 0.002x10E4

In decimal I would shift the coma to get the same exponents

1.2 x 10E3
0.02 x 10E3

So I can multiply the 2 numbers.

But in binary. I know obviusly how to convert to binary. But I pretend to normalize on binary not on decimal. Any hint about this?




Eóin

I think all FPU number are stored in normalised form anyway. Except the very smallest of them and depending on flags I believe you can tell the cpu to give an exception or not when it comes across one.


tenkey

Quote from: lucho on April 11, 2005, 12:35:17 PM
If I want to multiply 4 float numbers they must me normalizazed for example:

1.21 x 10E3 is different than 0.002x10E4

In decimal I would shift the coma to get the same exponents

1.2 x 10E3
0.02 x 10E3

So I can multiply the 2 numbers.

But in binary. I know obviusly how to convert to binary. But I pretend to normalize on binary not on decimal. Any hint about this?

It's not necessary to normalize or denormalize numbers for multiplication. It's only necessary for addition and subtraction.

1.21 x 103 x 0.002 x 104
= 1.21 x 0.002 x 107
= 0.00242 x 107

And then you can normalize the result if desired

= 2.42 x 104

Same for binary...

1.0012 x 23 x 0.00112 x 24
= 0.00110112 x 27
= 1.10112 x 24

Hardware uses normalized numbers because it can't create an any-size value. Normalizing keeps as many significant digits as possible at each computation step.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

lucho

I also need to sum and to substract. How can I normalize the numbers in assembly?

Eóin

What exactly do you need? How are you representing the numbers? "In binary" isn't an answer, there are many different ways of representing numbers, be they integer or not.

If you're doing math and just want to deal with floating points then use the FPU or SSE, if you have some very particular reason why you want to work with normalised numbers then you'll need to share it with us before we can help.

To repeat myself, all "regular" floating point number which are processed by the FPU or SSE are stored in a normalised form, you don't have to worry amount the mechanics of how they work unless you have special needs.

roticv

Eóin,

If you ask me, I think his teacher does not want him to use fpu.

AeroASM

Or he does not know about it...

When I started assembly, I saw the word "coprocessor" and gave up. I thought that you actually needed to buy an expensive coprocessor and install it onto a dual-processor motherboard. Thus I was deprived of floats for several months.