Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > design question
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 16th November 04:44
dom leonard
External User
 
Posts: 1
Default design question



<snip>

This has potential in that pages could include common code to cause menu
update based on their URL. I would not, however, attempt to get document
page code to *perform* menu update. More some kind of notification to
let frameset or contents page code know that the document frame URL has
changed.

Or I could connect the javascript to the hyperlinks that

Bad idea, no disagreement. Horrible maintenance problem.


I have used the 'notification' solution with no action taken if the
notified URL is not in the menu. Essentially common menu interface code
goes in a template file for frameset documents.

Another idea might be to run a timer script in either the frameset or
contents page which checks for *changes* in the url of the document
frame, and if an inactive menu link points to it, update the menu frame.
This suggests even static menu pages loaded from the server need to know
where hidden menu links lead.

There might be a small delay before menus update themselves (which is
exactly what I think menus should do) but this might actually be better
than page loading scripts using a notification scheme - clicking a menu
item to load a document frame can cause duplicate tracking if menu item
click and page loading both trigger contents tracking without additional
code to prevent the duplication.

Obviously a fully expanded contents page should be loaded initially by
the frameset for use in javascript disabled browsers.


Hope it helps,
Dom
  Reply With Quote


 


2 23rd November 03:14
christian christmann
External User
 
Posts: 1
Default Design question



Hi,

in my application I often need constant values depending on


#include <cmath>
const int getMinSigned10Bits()
{
return (- (int) pow( (float) 2, 10 - 1 ) );
}

The return value of this function is te minimal signed value
that can be representad with 10 bits. Might the castings
to int and flow lead to any problems or is this function
"stable"?
Do you see a more efficient way to solve this problem?

Regards,
Chris
  Reply With Quote


 


3 23rd November 03:14
kai-uwe bux
External User
 
Posts: 1
Default Design question


Are you sure, the floating point arithmetic cannot trigger an off-by one
error when the cast kicks in? I don't think that casts to rounding.

I don't think the cast is good.

template < unsigned bit_width >
struct MinMax {

static long const signed_min_value =
2 * MinMax< bit_width - 1 >::signed_min_value - 1;

static long const signed_max_value =
2 * MinMax< bit_width - 1 >::signed_max_value + 1;

static unsigned long const unsigned_max_value =
2 * MinMax< bit_width - 1 >::unsigned_max_value + 1;
}; // MinMax
template <>
struct MinMax<1> {

static long const signed_min_value = 0;
static long const signed_max_value = 0;
static unsigned long const unsigned_max_value = 1;
}; // MinMax<1>
#include <iostream>

int main ( void ) {
std::cout << MinMax<10>::unsigned_max_value << '\n';
}

No computation at runtime at all.


Best

Kai-Uwe Bux
  Reply With Quote
4 23rd November 03:15
ivan vecerina
External User
 
Posts: 1
Default Design question


: in my application I often need constant values depending on
: their bitwidth. For this purpose I wrote some static functions
: that look like this: :
: #include <cmath>
: const int getMinSigned10Bits()
: {
: return (- (int) pow( (float) 2, 10 - 1 ) );
: }
:
: The return value of this function is te minimal signed value
: that can be representad with 10 bits.
... when using 2's complement encoding.
: Might the castings
: to int and flow lead to any problems or is this function
: "stable"?
The floating-point calculation will be exact, unless there
is an overflow.

: Do you see a more efficient way to solve this problem?
Use the bit-shift operator:
return -( 1 << (10-1) );


Cheers,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
  Reply With Quote
5 23rd November 03:16
frederick gotham
External User
 
Posts: 1
Default Design question


Kai-Uwe Bux posted:

I haven't gone over that in detail, so I'll take your word for it that it
works . This can be achieved with just the *one* specialisation though.

(Let's assume that COMPASS is a compile-time assertion, and that the bit
quantity supplied to the template includes the sign-bit.)

Firstly, here's the max value:

#include <limits>

template<class T, unsigned bits>
struct IntMax {

/* COMPASS(std::numeric_limits<T>::digits >= bits); */

T const static MSBOnly = T(1) << bits - 1;
T const static val = MSBOnly | MSBOnly - 1;
};

The determination of the lowest value is slightly more complicated. First
thing though, we know that it will be 0 for unsigned types, so we can start
off with:

#include <limits>

template<class T, unsigned bits>
struct IntMin {

COMPASS(std::numeric_limits<T>::digits + 1 >= bits);
/* Note the "+ 1" */

T const static val_if_unsigned = 0;
};


Next, we must determine how to get the lowest value for a signed type --
but this will be dependant on the negative number system which is used. So,
first, let's determine the negative number system:

#define SIGNMAG 0
#define ONES 1
#define TWOS 2

#if -1 & 3 == 1
#define NUM_SYS SINGMAG
#elif -1 & 3 == 2
#define NUM_SYS ONES
#else
#define NUM_SYS TWOS
#endif

Next, let's see what the bit-pattern looks like for the min-value for each
number system. (Assuming 8-Bit numbers

SignMag: 1111 1111
Ones: 1000 0000
Twos: 1000 0001

Now we can put it together:

#include <limits>

#define SIGNMAG 0
#define ONES 1
#define TWOS 2

#if -1 & 3 == 1
#define NUM_SYS SIGNMAG
#elif -1 & 3 == 2
#define NUM_SYS ONES
#else
#define NUM_SYS TWOS #endif
template<class T, unsigned bits> struct IntMin {
typedef std::numeric_limits<T> Lim;
/* COMPASS(Lim::digits + 1 >= bits); */
/* Note the "+ 1" */

T const static val_if_unsigned = 0;

T const static signbit_only = T(1) << bits - 1;
/* Will this bit-shift work correctly? */

T const static val_if_ones = signbit_only;
T const static val_if_twos = signbit_only & 1;

T const static MSBonly = T(1) << bits - 2;

T const static val_if_signmag = signbit_only|MSBonly|MSBonly - 1;

T const static val_if_signed =
NUM_SYS == TWOS ? val_if_twos :
NUM_SYS == ONES ? val_if_ones : val_if_signmag;

T const static val = Lim::is_signed ? val_if_signed : val_if_unsigned;
};

--

Frederick Gotham
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666