# [CentralOH] (no subject)

Kurtis Mullins kurtis.mullins at gmail.com
Mon Dec 9 21:30:51 CET 2013

```I would probably use a combination of this post (
http://math.stackexchange.com/questions/10173/extract-each-digit-of-a-number)
and the Python Decimal library for precision.

Another alternative that seems apparent, but I haven't put much thought
into, is using the Decimal library, converting the number into a String,
and grabbing the digit by index.

Sorry I don't have more time to give you some sample code; I have to run.
If you can't solve it, I'll try to help out when I get some free time.

Good luck!

On Sun, Dec 8, 2013 at 4:10 PM, Louis Bogdan <looiebwv at gmail.com> wrote:

> I see that there are some questions about my explanation of what I'm
> trying to do.  Would it clarify things if my explanation read as follows:
> num(-1) denotes right-hand most digit of num in index position notation
> num(-2) denotes the 3rd position digit of num in index position notation.
>
> I don't know how to say it in computer language, that's why I'm asking for
>
>
> On Sun, Dec 8, 2013 at 2:49 PM, Brian Costlow <brian.costlow at gmail.com>wrote:
>
>> This was my quick & dirt response to an email from Louis, and Louis
>> reply, which I have not digested yet. I pointed him at the list as I'm kind
>> of buried with some other stuff this weekend.
>>
>>  You get the same rounding, will take any numeric or a string
>> representing numeric, no float imprecision, no weird string manipulation.
>>
>> >>> from decimal import Decimal as D
>> >>> multiplier_val = D('2000')
>> >>> quant_val = D('1')
>> >>> def custom_round(number):
>> ...   number = D(str(number))
>> ...   return (number * multiplier_val).quantize(quant_val) /
>> multiplier_val
>>
>> >>> custom_round(1.2340)
>> Decimal('1.234')
>> >>> custom_round(1.2341)
>> Decimal('1.234')
>> >>> custom_round(1.2342)
>> Decimal('1.234')
>> >>> custom_round(1.2343)
>> Decimal('1.2345')
>> >>> custom_round(1.2346)
>> Decimal('1.2345')
>> >>> custom_round(1.2347)
>> Decimal('1.2345')
>> >>> custom_round(1.2348)
>> Decimal('1.235')
>> >>> custom_round(1.2349)
>> Decimal('1.235')
>>
>>   I'm so familiar with the details of my invention and its ramifications
>> that I didn't provide you with enough details. to explain my approach. I am
>> looking to make this a subroutine for the following reasons:
>> 1. For various applications, there can be many number, N inputs.
>> 2. For each N input, there can be as many as 30 variable incremental
>> modifications to N, each modification requiring that "subroutine" to make
>> sure that N is in suitable form for later usage.
>> 3. The program to run this only requires the input of N and formula
>> created range of increments thus negating any access to N variations and
>> increments during  the cycle.
>> 4. So with this "subroutine" I have .0002" absolute positional accuracy
>> with .0005" increment control  and other accuracies can be obtained with
>> positional variations.  I hope this clarifies my original email.   Lou
>>
>>
>>
>>
>> On Sun, Dec 8, 2013 at 2:36 PM, Louis Bogdan <looiebwv at gmail.com> wrote:
>>
>>> I will start out by saying,"Have you heard that a LITTLE bit of
>>> knowledge is a dangerous thing?"  Well, I am the Poster Boy for that
>>> saying.
>>>
>>> num is calculated value 1.2346
>>> a=num(-1) is indicating the numeral "6" with negative indexing notation.
>>> b=num(-2) is indicating the numeral "4"   "         "
>>> "              ".
>>>
>>> if numeral "6" is greater than "7" make numeral "6" a "0" and increment
>>> the "4" to "5".
>>> elif numeral "6" is less than"3", meaning a "0", "1", or "2", make it a
>>> "0".
>>> else none of the above conditions apply, make numeral "6" a "5".
>>>
>>> EXAMPLE: 1.2340, 1.2341, 1.2342 become 1.2340
>>>                    1.2348, 1.2349 become 1.2350
>>>                    1.2343, 1/2344, 1.2345, 1.2346. 1.2347 become 1.2345.
>>>
>>> So with the "Bogdan" rounding, I am never more than .0002" off
>>> calculated position.
>>> I then divide the modified num 1.2345 by .0005 and get 2469 which is the
>>> number of steps required of the stepper motor to provide a movement of
>>> 1.2345" (-.0001" from theoretical.)
>>>
>>> I hope that explains MY way of talking to a computer.  How would you
>>> talk to Python and say the same thing and Python says,"MAN, I know what you
>>> want!?  Lou
>>>
>>>
>>> On Sun, Dec 8, 2013 at 11:34 AM, Andrew Fitzgerald <
>>> andrewcfitzgerald at gmail.com> wrote:
>>>
>>>> Hi Lou,
>>>>
>>>> Could you perhaps provide a summary of what that code is supposed to do?
>>>>
>>>> Right now you're assigning num the numeric value 1.2346 on the first
>>>> line.
>>>>
>>>> You're then attempting to call num as a function on the next 2 lines.
>>>>
>>>> This won't work because num hasn't been defined as a function anywhere,
>>>> and if it was the function is overwritten by the value 1.2346 on the first
>>>> line.
>>>>
>>>>
>>>> The part below that (if/else) looks like it should work if a and b are
>>>> assigned numeric values.
>>>>
>>>> -Andrew Fitzgerald
>>>>
>>>>
>>>>  On Sun, Dec 8, 2013 at 11:09 AM, Louis Bogdan <looiebwv at gmail.com>wrote:
>>>>
>>>>>  Hi folks @central oh/python:
>>>>>
>>>>>
>>>>>
>>>>> As a recent subscriber, I received notice of your Dec 9 meeting from
>>>>> Brian.  As I am working on a program to go along with a recently
>>>>> filed patent, and am totally new to Python, I sent him a proposed
>>>>> “subroutine”.  This is used repetitively within the program.  Since I
>>>>> sent it to Brian, I have done some more research and have come up with a
>>>>> better version as follows:
>>>>>
>>>>>
>>>>>
>>>>> num = 1.2346
>>>>>
>>>>> a = num(-1)
>>>>>
>>>>> b = num(-2)
>>>>>
>>>>> if a >7:
>>>>>
>>>>>      a = 0
>>>>>
>>>>>      b+ =1
>>>>>
>>>>> elif a<3:
>>>>>
>>>>>      a = 0
>>>>>
>>>>> else:
>>>>>
>>>>>       a = 5
>>>>>
>>>>>
>>>>>
>>>>> As each stepper motor step equals .0005” of movement, with the above I
>>>>> can get .0002” absolute positional accuracy with a .0005” control
>>>>> increment. I have looked at some of the Python “round” statements and
>>>>> examples and don’t fully understand them so as an “ole” retired engunear,
>>>>> (does 93 qualify me) I thunk up my own way of doing things.  Maybe
>>>>> some of you young ones can teach an ole man how to do things better.
>>>>>
>>>>>
>>>>>
>>>>> This routine also has application in several other projects I have
>>>>> under consideration. Would something like this, if it works, be a Python
>>>>> library item?
>>>>>
>>>>>
>>>>>
>>>>> If any of you can “tweek” the above into working order I would
>>>>> appreciate it.  I do have some other questions for you.  What do I
>>>>> need to buy to get started with RPi?  I will be using my Apple
>>>>> computer.
>>>>>
>>>>>
>>>>>
>>>>> Thank you for any comments you might have.  Lou Bigdan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> CentralOH mailing list
>>>>> CentralOH at python.org
>>>>> https://mail.python.org/mailman/listinfo/centraloh
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> CentralOH mailing list
>>>> CentralOH at python.org
>>>> https://mail.python.org/mailman/listinfo/centraloh
>>>>
>>>>
>>>
>>> _______________________________________________
>>> CentralOH mailing list
>>> CentralOH at python.org
>>> https://mail.python.org/mailman/listinfo/centraloh
>>>
>>>
>>
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> https://mail.python.org/mailman/listinfo/centraloh
>>
>>
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> https://mail.python.org/mailman/listinfo/centraloh
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20131209/66af21e8/attachment-0001.html>
```