News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Fixed Point Demo

Started by FORTRANS, March 12, 2015, 04:25:49 AM

Previous topic - Next topic

FORTRANS

Hi,

   On 1 March, 2015, in the thread "multiplying/dividing a positive
decimal number by a positive number" I posted a link to a DOS
program to display a fixed point number as binary, hexadecimal,
and decimal.  And it did not run on a Windows 7 machine.

   I made the mistake of writing my first "from scratch" Windows
program by translating it.  Sort of.  Thanks go to qWord, TWell,
and Dave for their postings in the forum that "explained" things
about console programming.

   Does anyone know of a simple .CHM reader for Windows 98
and 2000?

   Anyway, it is a toy program I use to calculate fixed point constants
when I needed them.  I translated the small one with 16.16 fixed
point.  There is a 32.32 version I may work on later.  Any bug
reports or comments?

Thanks,

Steve N.

Edit:  Updated the program, see below.
Original had four downloads.

SRN

raymond

Have you ever looked at the following which dates back about 10 years:
http://www.ray.masmcode.com/fixmath.html
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com

rrr314159

Presumably u like Fortran (judging by your handle)? I cut my teeth on Fortran approx 1968 to 1973. Limited but one great thing about it (compared to C, assembler): we never had a Fortran "guru": nobody ever asked "how do you do this ...?" about Fortran! (With exception, perhaps, of COMMON blocks). Everybody knew what it did; there were q's about the specification, or the system design - never the language.

Anyway, comments about your prog:

- no bugs.

- might as well include source code?

- better to use arrow keys rather than (or, in addition to) ( , . ) ?

- useful to have a "reset all" choice, perhaps? "Set all" too, while you're at it.

- be nice to take the next logical step and display the number as REAL8. I'd like to see 2 things,

1. REAL8 number and show the bit pattern of it, sign/exponent/mantissa
2. Translate the user-entered bit pattern to REAL8 (a very different thing!)

Of course u might not be interested in that, just a suggestion. Still, if u did it, u might *become* interested!

All these suggestions are like that, random top-of-the-head as I play with the prog, don't take seriously.

here's a little math puzzle. Notice that the decimal representation, after the decimal point, is always exactly as long as the last bit set. So if u set bit 13 there are 13 decimal digits after the point. That's not at all the case before the point. Up there, approx 3.3 binary digits are needed for each decimal digit, depending on other bits set. But, below the dec point it's as I say, last bit set = number of digits (exactly). Now, why is that? (If u already know this sort of thing like u know your name, sorry, ignore. Still, others might find it a puzzle)

@Raymond, nice library! Not as much fun as this colorful little utility, tho
I am NaN ;)

FORTRANS

Quote from: raymond on March 12, 2015, 05:18:31 AM
Have you ever looked at the following which dates back about 10 years:
http://www.ray.masmcode.com/fixmath.html

Hi Raymond,

   Yes, but long ago enough to have forgotten it.  I will have to
take another look.

Thanks,

Hi rrr314159,

Quote from: rrr314159 on March 12, 2015, 05:54:45 AM
Presumably u like Fortran (judging by your handle)?

   Of course!

QuoteI cut my teeth on Fortran approx 1968 to 1973. Limited but one great thing about it (compared to C, assembler): we never had a Fortran "guru": nobody ever asked "how do you do this ...?" about Fortran! (With exception, perhaps, of COMMON blocks). Everybody knew what it did; there were q's about the specification, or the system design - never the language.

   Pretty much my experience, started in ~1969.  Though I programmed
professionally in it till I retired.

QuoteAnyway, comments about your prog:

- no bugs.

   Yippie!

Quote- might as well include source code?

   It's my "first" such program.  Ugly, ugly, ugly.  And it is a mix of 8-,
16-, and 32-bit code that would probably make most of the regulars
here complain.  ; )

Quote- better to use arrow keys rather than (or, in addition to) ( , . ) ?

   Yes, the DOS one did.  The ReadConsole function I ended up
using to read single characters does not support "non-ASCII" keys.
It even ignores Escape and Delete, which are sometimes considered
ASCII.  One of the reasons for me to ask for a help reader.

Quote- useful to have a "reset all" choice, perhaps? "Set all" too, while you're at it.

   Nice ideas.  If/when I update it I will add those.

Quote- be nice to take the next logical step and display the number as REAL8. I'd like to see 2 things,

1. REAL8 number and show the bit pattern of it, sign/exponent/mantissa
2. Translate the user-entered bit pattern to REAL8 (a very different thing!)

Of course u might not be interested in that, just a suggestion. Still, if u did it, u might *become* interested!

   Well, fixed point and floating point are two different things.  If
I wrote something like that, it would be a separate program.

QuoteAll these suggestions are like that, random top-of-the-head as I play with the prog, don't take seriously.

here's a little math puzzle. Notice that the decimal representation, after the decimal point, is always exactly as long as the last bit set. So if u set bit 13 there are 13 decimal digits after the point. That's not at all the case before the point. Up there, approx 3.3 binary digits are needed for each decimal digit, depending on other bits set. But, below the dec point it's as I say, last bit set = number of digits (exactly). Now, why is that? (If u already know this sort of thing like u know your name, sorry, ignore. Still, others might find it a puzzle)

   Yes, I can show the answer if wanted.  Visually it is obvious.

Quote@Raymond, nice library! Not as much fun as this colorful little utility, tho

   Thanks for looking and commenting.

Regards,

Steve N.

raymond

QuotePresumably u like Fortran (judging by your handle)? I cut my teeth on Fortran approx 1968 to 1973.

Funny you should mention that. Actually, Fortran was the very first programming language I ever learned in the late 60's when the place where I worked got in one of those time-share terminals. Programs were stored on perforated tape.

I had learned enough in one week to be able to write two short programs for inventory control in my department (which continued to be used for some 15 years after they were later translated to some other language). Never had any use for computer programming for the next 15 years and forgot everything I learned about Fortran.
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com

hutch--

> and forgot everything I learned about Fortran

This is much the same approach I took with CPM, played with it in the early 80s, saw it was a toothless terror and bought a HP 11c calculator which functioned as my design tool for some years as well as for invoicing calculations. 10 years down the track I started on x86 PCs after having just about fully purged CPM from memory.

FORTRANS

Hi rrr314159,

   In honor of Pi Day, and your moniker, I updated the program to
use the cursor keys.  Added your idea of setting or resetting all
of the bits.  And assigned movement to PageUp, PageDown, and
Home.  And made an F1 message that mentions the extra keys
used.  Left in the X/x for exit, period and comma for movement
just for jollies.

   Thanks to Dave for posting an alternative console input routine
in another thread recently.  Seems to work very nicely.

Cheers,

Steve N.

rrr314159

FORTRANS,

I hope u posted it at 9:00 your local time, to maximally honor Pi ... and that you're getting more comfortable with Windows programming as you go along. I've been spending some time with Floyd and Steinberg which if I remember correctly was once an interest of yours. I made some 16-color images, from 24-bit depth, and they looked like they had freckles or acne. Not as simple as it appears at first glance

Quote from: hutch...CPM...was a toothless terror...

Can't agree there. When I got an S100 system with Z80 @ 4 MHz, 64K RAM, dual floppies (141 K each, as I remember) - and CP/M -  for thousands of dollars, I was in heaven! That was late 70's or so. Used Wordstar, fine little editor, and programmed directly in octal codes, so the "assembler" was blazing fast; especially since 10,000 lines was a huge prog in those days. I also had an HP calculator (forget the number) for scientific work. Come to think of it, I suppose you were trying to use Fortran on CP/M? Yes, for scientific (including, e.g., trig functions) it was a "toothless terror" compared to the HP.

Quote from: raymondFortran was the very first programming language I ever learned in the late 60's when the place where I worked got in one of those time-share terminals. Programs were stored on perforated tape.

Me too, except I was still in high school. Funny story, one day teacher booted me out of class for not wearing a tie (I'd simply forgotten) so, instead of trekking back to the dorm, I wrapped some perforated tape around my neck instead. Got 3 demerits; all the other students envied me. BTW, don't get me started on what I could accomplish in one week back then

Reading the above it occurs to me, that warm glow I get reminiscing probably morphs into sheer boring irrelevance when viewed from the perspective of anyone else. When u love to talk about the past instead of the future you're getting old
I am NaN ;)

raymond

QuoteWhen u love to talk about the past instead of the future you're getting old

Yes, but the past is what you built on.

My next adventure with programming came in the mid 80's when I purchased a second-hand TRS-80 with a 64K expansion interface ($500 with 4 floppy disc drives and a TTS printer). I think my most memorable program (based on a challenge from my son) was to extract the square root of any input number to an accuracy of 9,999 decimal places!!!
Whenever you assume something, you risk being wrong half the time.
http://www.ray.masmcode.com

rrr314159

TRS-80 in mid-80's? Obviously computers weren't your main thing, but your courage is admirable. And, it never even occurred to me to extract anything to 9999 decimal places, even on color PC's and Fat Macs, so that's admirable too.  In fact it still hasn't occurred to me! I think u have me beat in the floating point dep't.

That was the era of my devastating decline from mathematics (and, computers) into the nether hell of management, proposals, meetings in Crystal City ... the only good thing, I looked sharp in a suit. And, u should have seen me hanging around Newport, when trying to extract money from NUSC, in a pink alligator shirt and Kelly green pants - you'd never forget it (hard as you might try). No doubt I had u (or anyone) beat in the sartorial dep't!

Still (back to computer accomplishments), towards the end of the decade, I learned how to put together a project of millions of lines in Ada, C, 68000 assembler (forgot just how many lines), and was no slouch as a technical director, so perhaps it wasn't a total waste
I am NaN ;)

dedndave

Ray is our distinguished eldest forum member   :t

that's really saying alot, because many of our members are in the "over 55 club"   :P

besides being an FPU whiz, he's one of the administrators of Project Euler

FORTRANS

Hi,

Quote from: rrr314159 on March 15, 2015, 02:23:52 PM
FORTRANS,

I hope u posted it at 9:00 your local time, to maximally honor Pi ... and that you're getting more comfortable with Windows programming as you go along.

   I was a bit slow there.  And maybe.

QuoteI've been spending some time with Floyd and Steinberg which if I remember correctly was once an interest of yours. I made some 16-color images, from 24-bit depth, and they looked like they had freckles or acne. Not as simple as it appears at first glance

   Yes, I got the "acne" and bleeding when the palette selected
was a smaller volume than the original color space.  And there
were large areas of one kind of color.  The propagated error gets
too big.  One way to help this is to drop the 1/16 F-S term to
damp the error propagation a bit.

   One way that did come to mind was to use the corners of the
color cube for eight colors, and reduce the 24-bit image to eight
colors for the 16 color palette.  In my implementation, it was
generally not as good as damping the error.

Regards,

Steve N.

FORTRANS

Hi,

   I made a quick translation of the 32:32 version of the fixed point
display program.  Let me know if there are problems I have overlooked.
The set all and reset all still work, but are no longer mentioned.  And
there are a few other differences with the 16:16 version.

rrr314159

#13
Hi FORTRANS,

Sorry, I was hors de combat for a while, glad you're programming away, it's the ideal hobby - fun, good mental exercise, and who knows someone might pay for the results some day!

The only lacuna in the 32 bit version is the help key: F1 doesn't work any more. Your user base wants it back! You dropped the movement keys , and ., and X/x; might as well. Esc is standard.

I think I would have made the PgUp/Dn keys move one nibble (4-bits) instead of go to the ends, use home and end for that. Admittedly it's useful to have a "centering" key (home is doing that now), but 4-bit group movement wld be good.

Of course none of this is important but as long as I'm at it might as well dump my impressions ...

Suppose the user could navigate to the hex numbers on the second row with up/down arrow. Then use 0, 1, 2, ... e, f to set one hex digit. Of course the binary bits would update accordingly.

Now, the only real problem is flickering. You know, the whole display flickers when any key is touched, eg arrow keys. I've never done a DOS prog like this (well, so long ago I've forgotten) but we all run into this same problem with any windows prog. The trick is to synch the update with the display refresh. Sometimes just double-buffering takes care of it well enough. Of course this is just a simple prog done for exercise, we could say flickering doesn't matter, still you should figure how to get rid of it - will apply to any DOS prog you ever write, that has a user interface.

FAIK it can't be done readily with DOS prog. If so maybe it's time to graduate to a real Windows prog. dedndave can tell you all about it, give you samples, even write the whole thing for you ... if only he could do the dishes also ...

Quote from: FORTRANSOne way to help this is to drop the 1/16 F-S term to damp the error propagation a bit.

hmmm ... beginning to sound like work :icon_confused: But I'll give it a try

Quote from: dedndaveRay is our distinguished eldest forum member   :t ... that's really saying alot, because many of our members are in the "over 55 club"   :P ... besides being an FPU whiz, he's one of the administrators of Project Euler

- Yes that's saying a lot: older than you! Wow! As a young man (only 63, barely middle age) my mind boggles. However - once you get past 60 or so I think health is more important than chronological years. You sort of coast along, all the way into 90's if lucky, until you get the "big one" - some horrible affliction like cancer, liver, heart, bad car accident etc. Then suddenly you're really old. So I propose seniority should be based not on how many years lived, but how many few left to live. That would put me in the top spot, most likely.

Project Euler is cool, I might sign up, the problems are fun, I'm getting tired of Dudeney. But u might as well give up on trying to trump my accomplishments. If you'd seen me in my Newport days, dressed to the nines, you'd realize I've achieved #1 in my field - sartorial extravagance - and am rather blase about people who are merely "near the top" in theirs. 8)
I am NaN ;)

FORTRANS

Hi rrr314159,

Quote from: rrr314159 on March 21, 2015, 04:49:00 AM
The only lacuna in the 32 bit version is the help key: F1 doesn't work any more. Your user base wants it back! You dropped the movement keys , and ., and X/x; might as well. Esc is standard.

   Really?  How would you want the key descriptions to read in the
program main and the help string?

Quote
I think I would have made the PgUp/Dn keys move one nibble (4-bits) instead of go to the ends, use home and end for that. Admittedly it's useful to have a "centering" key (home is doing that now), but 4-bit group movement wld be good.

   Well, my usage would not use byte or nybble movement.  I tend
to toggle descending bits to approximate a wanted constant value.
Maybe others will weigh in.

Quote
Of course none of this is important but as long as I'm at it might as well dump my impressions ...

Suppose the user could navigate to the hex numbers on the second row with up/down arrow. Then use 0, 1, 2, ... e, f to set one hex digit. Of course the binary bits would update accordingly.

   Again, my usage wouldn't use this.  Except as a kind of game?
Anyone else comment?  I guess you could use it to double check
values in someone else's program that was in a hexadecimal form.


QuoteNow, the only real problem is flickering. You know, the whole display flickers when any key is touched, eg arrow keys. I've never done a DOS prog like this (well, so long ago I've forgotten) but we all run into this same problem with any windows prog. The trick is to synch the update with the display refresh. Sometimes just double-buffering takes care of it well enough. Of course this is just a simple prog done for exercise, we could say flickering doesn't matter, still you should figure how to get rid of it - will apply to any DOS prog you ever write, that has a user interface.

   Well, this is a Windows console program, not a DOS program.
See the original posting for a reference to a thread that mentions
the original DOS program.  Oh well, here it is again.

http://www.masmforum.com/archive2012/5486_FIX2DEC.zip

   Flickering?  Oh.  Not bad here.  Actually if you had not mentioned
it, I would not have noticed.  But it does occur.  Well I can cure
that for movement keys easily.  Top of the loop recalculates everything,
redraws it, then waits for a keystroke, and processes it.  Just add
another label to bypass the redrawing for movement keys.

   BTW, you mentioned source code above somewhere.  The DOS
versions of this program were used as a starting point for another
program that was posted in the Soap Box.  DOS code, but the "logic"
is more or less unchanged.  Search for "Register Visualization".
Around the end of April 2013.

Regards,

Steve N.