473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Measure class, precision, significant digits, and divmod()

Hey all.

My thanks to all who have responded so far with my other questions. It
is much appreciated.

Some background on what I'm doing (a good explanation can be found at
http://www.hazelwood.k12.mo.us/~gric...eb/phys8.htm): When
measuring, there is some uncertainty as to the *exact* value; so, when
doing calculations with these measured numbers, one should not present
an answer that seems more accurate than the source. For addition and
subtraction this means the final answer cannot be more precise than the
least precise input: 5.0 + 21.23 = 26.2 (first number only measured to
the tenths, so answer only good to the tenths); for multiplication and
division this means the answer cannot have more significant digits than
the input with the fewest significant digits: 231 * 0.25 = 58 (0.25
only has two significant digits, so answer only has two significant
digits). Important point -- counting is not subject to precision error.

As I have mentioned before, I am making this Measure class for two
reasons: experience with unit testing, I like playing with numbers, I
am unaware of anything like this having yet been done (okay, three
reasons ;).

So far, I have the init, add, sub, mul, div, cmp, neg, pos, and abs
done, and I'm ready to tackle floordiv, mod, and divmod... okay, maybe
'ready' is too strong a word -- one of the obstacle's I'm facing is that
I, myself, don't have any real use for this class, so I'm stuck on
deciding how floordiv, mod, and divmod should function. As mentioned
above, counting is precise... so should divmod (a // b, a % b), which
returns the count of times b goes into a, and the remainder, be an exact
number, or should it behave like floor(a / b), and preserve the inherent
inaccury present in the measured value a? Should I have floordiv
preserve inaccuracy, and divmod be exact?

Any and all feedback welcome, particularly from anyone who might
actually use the Measure class. ;)

~Ethan
Jul 15 '08 #1
3 1917
Ethan Furman wrote:
Hey all.
<snip>
>
As I have mentioned before, I am making this Measure class for two
reasons: experience with unit testing, I like playing with numbers, I
am unaware of anything like this having yet been done (okay, three
reasons ;).
<snip>
>
Any and all feedback welcome, particularly from anyone who might
actually use the Measure class. ;)

~Ethan

I have been following this thread with interest, because i am doing
something similar, namely writing python to provide myself with
experience with unit tests and i like playing with numbers.

In my case the numbers are 'long rationals' (infinite precision)
and will include both floats, the decimal type, extended 'decimals'
-- i.e. possibly with a repeating expansion (or in any base) --
and finite continued fractions as derived classes.
I also hope to deal with repeating continued fractions later.

+++++++++++++++++++++++++++++++++++++++

My principal interest in your work, however, is in the use of
unit tests as a pedagogical method of teaching programming, whether
self-taught or taught by an instructor.

The students would be taught how to __run__ a unit test-suite
at as early an opportunity as possible. I can't see
why an eleven or twelve year old should not be able to cope
with it in hour one or two of a carefully structured course.

What is needed for such an approach is a copy--in a public
place--of your unit tests for all methods
that are really part of the funtionality; together with
blanked-out definitions for them (i.e just the first line,
any in-code documentation, and 'pass' ).

You would not include any 'internal' methods that are merely the way
__you__ happened to achieve the result.

The programming 'exercise' would then be for the students, or
groups of students, to roll their own version until their code
passed all the unit tests.
Jul 15 '08 #2
Ken Starks wrote:
Ethan Furman wrote:
>Hey all.
<snip>
>>
As I have mentioned before, I am making this Measure class for two
reasons: experience with unit testing, I like playing with numbers, I
am unaware of anything like this having yet been done (okay, three
reasons ;).
<snip>
>>
Any and all feedback welcome, particularly from anyone who might
actually use the Measure class. ;)

~Ethan
[snip]
+++++++++++++++++++++++++++++++++++++++

My principal interest in your work, however, is in the use of
unit tests as a pedagogical method of teaching programming, whether
self-taught or taught by an instructor.

The students would be taught how to __run__ a unit test-suite
at as early an opportunity as possible. I can't see
why an eleven or twelve year old should not be able to cope
with it in hour one or two of a carefully structured course.

What is needed for such an approach is a copy--in a public
place--of your unit tests for all methods
that are really part of the funtionality; together with
blanked-out definitions for them (i.e just the first line,
any in-code documentation, and 'pass' ).

You would not include any 'internal' methods that are merely the way
__you__ happened to achieve the result.

The programming 'exercise' would then be for the students, or
groups of students, to roll their own version until their code
passed all the unit tests.
Definitely an interesting idea. I'm not sure if I should be worried
about the 12-13 year old students tackling a complex class such as a new
number class, or if I should prepare to be embarrased by how much
simpler they are able to make equivalent code! ;)

At any rate, once I'm done the code will be released under a very
friendly license, so you'll be free to do that should you desire to.

~Ethan
Jul 15 '08 #3
I have a small project for further development
in eclipse, using the pyDev plug-in.

I am working on foo.py and bar.pyc is also
in the directory.

bar.py is not in the directory; it is someone
else's (confidential) file, and I don't get
the python source.

Can I run bar.pyc from eclipse ?
Jul 16 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: mrstephengross | last post by:
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 --> 3...
2
by: Lukas Bradley | last post by:
Using MySQL 4.0.12, is there a way to specify significant digits for a mathematical operation within a SELECT? In other words, the query "select 5/213" defaults to two significant digits (0.02)...
8
by: David Corby | last post by:
Hi everybody, I've got a problem. I'm trying to round a double to a particular number of significant digits, in this case 5, but I can't figure out a way around getting _exactly_ what I want...
6
by: Jonny | last post by:
If you run the following code , you will get 1.12346e07 as the output. What do I need to do if you want all the significant digits output, like 1.123456789e07? #include<iostream> using...
3
by: BuddyWork | last post by:
Hello, Does .Net support significant figures if so can someone point me to the right direction or example code? Thanks,
7
by: Michael Howes | last post by:
MSDN documentation for format strings seems ambiguous. It's says things like "significant digits or number of decimal places" all over the place. Well those two things are different. How do I...
2
by: Mukesh_Singh_Nick | last post by:
What is meant by the "most significant digits" in the following statement? <BLOCKQUOTE> With %g and %G, the precision modifier determines the maximum number of significant digits...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.