Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > sscanf question

Reply
Thread Tools

sscanf question

 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      12-16-2012
Eric Sosman <(E-Mail Removed)> wrote:

(snip, I wrote)

>>> S/360 style BCD provides up to 31 digits for add and subtract.
>>> The limits for multiply and divide are more complicated, but
>>> PL/I (F) allows up to 15 digits.


>>> So, a little more than 32 bit binary.


>> This wasn't machine-based BCD. This was through a library,
>> in a 32-bit machine. I do not recall if there was long long
>> (64 bit) support. Probably wasn't.


> It was "machine-based" at least to the extent of having
> instruction codes defined to perform it. See pages 34ff of
> <http://bitsavers.informatik.uni-stuttgart.de/pdf/ibm/360/princOps/A22-6821-0_360PrincOps.pdf>.


> On some S/360 models the hardware to implement decimal
> opcodes was an optional feature (the "Commercial Instruction
> Set option"). But then, on some S/360 models floating-point
> hardware (the "Scientific Instruction Set" option) was also
> an optional feature, and I haven't heard anyone claim that
> S/360 floating-point wasn't "machine-based."


Well, the smaller S/360 processors were all microcoded, so the
real question was optional microcode for both the decimal
and floating point case.

I believe even on machines without the floating point
option that the registers were still there.

The decimal instructions are storage to storage, except
for CVB (storage to register) and CVD (register to storage).
(Those are ConVert to Binary and ConVert to Decimal.)

Also, the 360/91 didn't implement the decimal instructions,
though it did have CVB and CVD. The OS based emulation mostly
used those instructions to do the emulation.

-- glen
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      12-16-2012
On Dec 14, 11:50*am, "BartC" <(E-Mail Removed)> wrote:
> "glen herrmannsfeldt" <(E-Mail Removed)> wrote in message
>
> news:kae67t$isr$(E-Mail Removed)...
>
> > BartC <(E-Mail Removed)> wrote:
> >> Because integers don't do fractions very well. Not without using special
> >> methods, at which point it becomes easier to just use floating point.
> >> But if you then have to calculate 15.9% tax on $53.49, it's a lot
> >> easier with floating point.

>
> > Take 5349 (cents) multiply by 159 and then divide by 1000 to get the
> > truncated tax in cents. But with tax, you have to watch the rounding.
> > If you want the rounded value, add 500 before dividing by 1000.

>
> OK, by using 'special methods' as I mentioned. You've now also introduced
> the arbitrary figures 10 (10*15.9), 500 and 1000, and presumably need to
> impose some arbitrary convention as to how percentage values are going tobe
> represented in the program (I guess you can't just have 15.9 or 0.159).
>
> At this level of program, just using floating point is a lot easier! You
> just need to round to a cent at every stage, taking care when values are
> negative; one little function.
>
> > With floating point, the intermediate values might be rounded.

>
> Do you have a calculation where that rounding (which will be to the
> low-order bits of the representation) will actually give a different result
> to doing the whole thing with integers? (And with ordinary amounts that are
> likely to be encountered.)
>
> > Multiply be the value with four decimal places, after moving the decimal
> > point to the right four places, then divide by 10000. Not hard at all.

>
> No. Waste of time inventing floating point, really!


and rather horrid and easy to get wrong floating point! Fixed point is
just nasty- leave it to the embedded programmers.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sscanf question sieg1974@yahoo.com C Programming 5 11-23-2006 07:39 PM
Programmer wannabee question about sscanf broeisi C Programming 10 03-05-2006 05:16 AM
sscanf() question? jchludzinski@gmail.com C Programming 5 06-09-2005 05:45 PM
sscanf fixed-width integer question Brent Lievers C Programming 8 04-26-2004 05:55 PM
Question on sscanf Dan Smith C Programming 3 08-14-2003 12:42 AM



Advertisments