lower number



  • 1. Strange Computations
    XXXX@XXXXX.COM wrote: > This program takes a number and keeps adding a small fraction to it, > but even once its real value is doulbe its starting value, the computer > believes it is less than what it started as. > > Can we draw any deeper meaning from this? I'll ask you. > > #include <stdio.h> > #include <math.h> > > int main() { > > double d=0.000001; > > int buf=1.0; > > if(1.0==buf) > printf("1: true\n"); > > buf=buf-d; > > if( 1.0>buf+d) { > > for(int cnt=0; cnt<1000000; cnt++){ > buf=buf+d; > if( (1.0>buf) ) > printf("%d: error\n",cnt); > } > > } > return 0; > > } [Posted to alt.magick; I added comp.lang.c to the group list.] We at alt.magick aren't sure whether this guy is a troll or not. He claims to be a famous author in the computer programming industry. He didn't reveal his name to us, but a few guys here were able to discover that his name is Herbert Schildt. Anyway, I'll give him the benefit of the doubt and assume that Mr. Schildt has not heard of comp.lang.c, which someone here suggested would be the appropriate newsgroup for his posts. We suspect his computations are... 'floored'. Regards, Nihilist 10=1
  • 2. compiling ffmpeg -> missed dlls
    thanks, but i already looked on ffmpeg, also on google.. but i asked here, because i'm not a good c++ developer, so i don't know if there are some options to compile a code for get an dll.. Thanks, Marco
  • 3. Converting C# DateTime field into Native C object
    Hello everyone, I am working on a project when I have to convert a C# program into Native C for speed purposes. I am using a .dll that creates a DateTime object. Obviously, there is not DateTime object in Native C, but I would like to know if there is a work-around to parse out the day/month/year from this DateTime object. Any ideas?
  • 4. progrm to find a substring in a string
    Hi all,Could anybody tell me the most efficient method to find a substr in a string.

lower number

Postby temper3243 » Sun, 21 May 2006 01:42:20 GMT


If i have an array like {1,4, 10, 15 , 20 , 30 }  of size n , now if i
want to search for number

25 , i should get 20 , if i search for number 11 i hould get 10 , if i
search for 4 i should get 4, if i search for a number and it doesn't
exist i should get the lower number between which it lies. All numbers
are bound to lie between 1 and n.

Can you tell me a easy way to do it.

Re: lower number

Postby bert » Sun, 21 May 2006 02:07:46 GMT

Just write some C code to do it.  If it doesn't work,
post the code, then somebody here will help you.

Re: lower number

Postby Clever Monkey » Sun, 21 May 2006 02:09:02 GMT

Brute force: Iterate through the array (pre-sorted or not, depending on 
how scalable you need this to be).  Does the current pass the <= test? 
Save it, but only if it is larger than the previously saved value. 
Continue to the next item and repeat until done.  Your saved value has 
the last item that matched your criteria.

Of course, since the exact test is a special case, it would be smarter 
to short-circuit if you find that value at any point.

I'm sure there are much better and more refined algorithms.

Re: lower number

Postby pete » Sun, 21 May 2006 03:19:21 GMT

/* BEGIN new.c */

#include <stdio.h>

int comparison(const void *arg1, const void *arg2);
void *HW_search(const void *key, const void *base,
                  size_t nmemb, size_t size,
                  int (*compar)(const void *, const void *));
int main (void)
    int x, *found;
    int array[] = {1,4, 10, 15 , 20 , 30 };
    int targets[] = {25, 11, 4, 1, 2, 3, 23};

    for (x = 0; x != sizeof targets / sizeof *targets; ++x) {
        printf("Searching array for %d\n", targets[x]);
        found = HW_search(
            targets + x, 
            sizeof array / sizeof *array, 
            sizeof *array,  
        printf("found %d\n\n", *found);
    return 0;

int comparison(const void *arg1, const void *arg2)
    return *(int*)arg2  > *(int*)arg1 ? -1
         : *(int*)arg2 != *(int*)arg1;

void *HW_search(const void *key, const void *base,
                  size_t nmemb, size_t size,
                  int (*compar)(const void *, const void *))
    int comp;
    size_t odd_mask, bytes, middle, high, low;
    const unsigned char *array, *found;

    found = NULL;
    if (nmemb != 0) {
        odd_mask = size ^ size - 1;
        array = base; 
        low = 0;
        high = nmemb * size;
        do {
            bytes = high - low;
            middle = (bytes & odd_mask ? bytes - size : bytes) / 2
                + low;
            base = middle + array;
            comp = compar(key, base);
            if (comp > 0) {
                low = middle;
            } else {
                high = middle;
                if (comp == 0) {
                    found = array + high;
        } while (bytes != size);
    return (void *)(found == NULL ? array + middle : found);

/* END new.c */


Re: lower number

Postby jaks.maths » Thu, 01 Jun 2006 16:30:35 GMT

Assuming that array is sorted one.

int main()
int a[20],i,j,n;
printf("\n enter the value to be searched");
return 0;

Similar Threads:

1.the lowest number of comparisons in string matching


I'm looking for the algorithm which does the lowest number of
comparison for the string matching problem (in the worst case).

I know that the complexity is liniar in the length of the strings, but
I'm interested in finding the actual number of comparisons.

The lowest number (theoretical) is m-n+1, but as far as I know no
algorithm has achived this limit.

(where m is the lenght of the text and n is the length of the pattern).


2.sort a number highest to lowest


     I'm trying to create a function that will sort a number's digits
from highest to lowest.

For example

1000 - will become 0001

or 1234 to 4321

    Is it better to covert the number to a string first then sort? or
is there a better way to do it?
    I just need some clues on how to do it. I've tried to search some
materials on how to do it but I only saw how to sort a 'LIST' but not
just a number.
    Thanks for the help

3.c is a low-level language or neither low level nor high level language

   I have a doubt that 'c' is low level language or neither low level
nor high level language.please give me details.
with regards,

4.Test vote 2005: 1.0 shall mean fp-number ONE,not double-number TEN

5.denotations Test vote 2005: 1.0 shall mean fp-number ONE, not double-number TEN

In article < XXXX@XXXXX.COM >,
Brad Eckert < XXXX@XXXXX.COM > wrote:
>The interpreter's number handler should be a defered word or vector.
>The ANS standard specifies very few variables, like STATE and BASE. It
>could specify a variable to hold the xt of the number handler.
>ENVIRONMENT would tell you if the system allows you to re-vector it.

As you all know by now, I am of the opinion that 
  the "number" handler should be extensible and modular
  extending number handling should be oblivious to current number
    handling 1)
  number handler is a bad name, because it handles strings and 
    application dependant denotations, such as labels in an assembler.
  So lets talk about denotation handling.

1) This is as far as it goes. you are right that some numbers
could be double as well as floating. But in Forth there is no 
floating context (I am doing perl at the moment, they are talking
about scalar and array context. It makes me appreciate the 
context free ness of Forth.) So the notation shoudl make clear
what kind of number it is. We can't have it any other way in


Groetjes Albert

Albert van der Horst,Oranjestr 8,3511 RA UTRECHT,THE NETHERLANDS
        One man-hour to invent,
                One man-week to implement,
                        One lawyer-year to patent.

6. Test vote 2005: 1.0 shall mean fp-number ONE, not double-number TEN

7. number parsing hooks (was: RfD: Number Prefixes)

8. real number to 16 bit signed number

Return to c


Who is online

Users browsing this forum: No registered users and 24 guest