News:

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

how to print extended numbers?

Started by thomas_remkus, August 27, 2009, 03:12:43 AM

Previous topic - Next topic

FORTRANS

Quote from: dedndave on August 30, 2009, 02:24:39 PM
but i think that is only a valid equation for N > 0 - if we DID plug a 0 in for N, Q = 1

   Right, which is the number of states possible with no choices.
One of those nice, valid answers that doesn't have much use.

Quote
i feel i should return some kind of a valid string pointer in all cases
(if they try to print a string at address 0, it crashes with access violation, as an example)

   But aren't they passing to you the pointer to the string
buffer?  If they send you a zero, what are you going to do
with it?

?,

Steve N.

dedndave

QuoteIf they send you a zero, what are you going to do with it?

hmmmm.....
my first "impulse thought" would be to return a pointer to a 0-byte in the .text or .rdata segment - lol
i suppose the right thing to do is to pass them back their 0 and let them crash - lol
garbage in - garbage out, right ?

i don't want to add a bunch of overhead to the routine that is going to slow it down
i just want to do "the right thing", whatever that is
i am just now noticing that windows list of error descriptions sux rox - lol
they do not have these messages, which i would think seem rather natural choices:
1) The requested operation would cause stack overflow.
2) The requested operation would cause output buffer overflow.
(no wonder windows is full of security issues - they don't even have a decent code set aside for simple buffer overflow)

on the other hand, they have 458 different error codes that all generate the same description:
"Waiting for a process to open the other end of the pipe." (error codes 536-993)
at least they got that one covered - lol

the idiot that made the list was probably out in the back alley smoking crack with
the guy from intel that decided they didn't need LAHF/SAHF on 64-bit processors

EDIT - here's another example:
error 122 - "The data area passed to a system call is too small."
why didn't they just say, "The output buffer is too small."
because they used the word "system", we can't use it for non-API functions ?

and another:
error 87 - "The parameter is incorrect." (very helpful - lol)
why not take some of the "pipe" error codes i mentioned above and say:
"Paramater 1 is invalid"
"Paramater 2 is invalid"
"Paramater 3 is invalid"
"Paramater 4 is invalid"
"Paramater 5 is invalid"
"Paramater 6 is invalid"
"Paramater 7 is invalid"
"Paramater 8 is invalid"

there isn't one for "The input value is too large.", either - lol

FORTRANS

Hi,

Quotegarbage in - garbage out, right ?

   Right.  I really don't think you have much choice.
As with:

Quotethe idiot that made the list was probably out in the back alley smoking crack with
the guy from intel that decided they didn't need LAHF/SAHF on 64-bit processors

   Just when you think you've made it idiot-proof, they
come up with a more persistant idiot.  The example with
LOOP being too fast for Micro$oft's installer, so instead of
fixing the installer, break the LOOP instruction comes to mind.

   Ah well, Some times the best thing to do really is do nothing.

Best regards,

Steve N.

dedndave

i am half-tempted to return pointers to my own predefined error strings
it's simple, it probably takes less space than the code to do otherwise, and it helps the guy debug his code

FORTRANS

HI,

   I have my fixed point routines working, more or less, more checking
for errors is needed.  Anyway, I can have hundreds of digits on either
side of the decimal point.  If I was going to do it over, I think I would
just do floating point routines.

   Currently implemented (Unsigned):
  Addition,
  Subtraction,
  Division using shifts and subtracts,
  Multiplication using shifts and adds,
  Multiplication using multiply and accumulate,
  Display fixed point number as decimal,
  Convert ASCII to fixed point number,
  and Copy.

   I can't see any real use for this type of math package.  A floating
point package with extended precision might be useful.  But the
80-bit FPU has got to cover most problems nicely.  If I don't just
forget about it, the next steps would be, a compare routine, a
shell to handle signed arithmetic, and possibly, a square root.

Anyway,

Steve N.

dedndave

ok - hopefully this is the last revision for the unsigned routine
i had thought about combining signed and unsigned into one routine
but, i considered there is no reason the unsigned routine should suffer speed loss (small diff)
so, i changed the plan to creating one routine for unsigned values and one for signed values
this is the unsigned version - i am working on the signed version
there are a couple ways to do it, so i have to write it both ways and compare performance
i may combine them into one routine, still - see how it goes
anyways, here is unsigned - revision 5 - with a test program

thomas_remkus

Tested on my 1.6 atom and everything was quick except for the last ... but that's a really big number!! And I hope you don't mind me disecting what you did to understand better .. and ask questions.

FORTRANS

Hi,

   Looks good, congrats.

Regards,

Steve N.

dedndave

#38
thanks guys
yes - that IS a big number - lol - 128 Kb+ result string
i found a minor mistake on my part
i test to see if, when the input size is converted to bytes, it overflows (cf)
if it does, i flag it as a "input too large error" - it should be "invalid input length"....

        dec     edi               ;point to last dword
        shl     edi,2             ;in bytes
        jc      A2Str7            ;error - input length too large

should be....

        dec     edi               ;point to last dword
        shl     edi,2             ;in bytes
        jc      A2Str6            ;error - input length invalid

i dunno what i was thinking - lol
it won't affect normal operation - i will update when i finish the signed version

dedndave

ok guys - i need your input again
the best way to handle negative values (signed, of course) is to convert them to positive values first
it takes less time to do that than it would to extract decimal digits from a signed value, which would also slow down positive values
the overhead is not that signifigant, as the code is executed once prior to the ascii conversion loop
so - the question i have is this:
would it be better to have one routine that handles signed and unsigned formats (requiring an additional parameter)
or to have two seperate routines, one for signed, one for unsigned
seeing as how there are only a few people interested in this thread (lol), we will have a small vote-count

EDIT - nevermind guys - lol
the best solution: write all three routines and let the guy pick his own poison

raymond

I had the occasion during the past week to play myself with bignums because of a math problem published on one of those sites which I follow. The first part involved raising numbers to some power, dividing them by a number under 1000, and then multiplying them together. The final step was to convert the resulting binary number (almost 1100 bytes) to decimal and add up the digits to provide the required answer. I guess my eventual algo was proper because the submitted answer was accepted as correct.

If anyone is interested to try it, here's the description of that problem.

Quote3!=6

The divisors of 6 are : 1, 2 , 3 and 6

The sum of the divisors of 6 is 1+2+3+6=12.

The sum of the digits of 12 is 3.

It can be calculated that the sum of the divisors of 10! is 15334088.
The sum of the digits of 15334088 is 32.

Find the sum of the digits of the sum of the divisors of 1000!

As a side note, my algo ran in less than 3 ms.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dedndave

that's cool Ray - lol
you saw the length the routine posted above could handle ?
i am trying to get ling long kai fang going - it can handle even longer ones
just haven't had much time to spend on it
as for 3 ms ? we don't understand "ms" - we need clock cycles - lol

thomas_remkus

Hutch ... is that a ProjectEuler puzzle or some other site?

dedndave

that's Raymond - not Hutch - lol
and i think that is the site he likes to tackle - i have seen him mention it in other posts
Ray is our resident FPU expert - his site has a few nice libraries and a great "plain-English" FPU tutorial
the tutorial is also part of the masm32 package (\masm32\tutorial\fputute)
Ray's site:
http://www.ray.masmcode.com/

raymond

Quoteis that a ProjectEuler puzzle or some other site

It was published on another "minor league" site where problem difficulty is generally at the low end of the scale. This one came out of the blue and was actually proposed by one of the gugus at PE. It may be easy coding for those using HLL languages having access to some bignum library.

The only real difficulty is to know how to compute a sum of divisors without actually identifying all those divisors. For example, using your calculator, you can determine that 1000! is equal to approx. 4*102567. But that big number would then have almost 3*10106 distinct divisors! :eek
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com