Nervous ticks in C - a reminder of the cruel logic of logic [Software]

posted by ElMaestro  – Denmark, 2018-03-15 11:24 (1839 d 21:10 ago) – Posting: # 18549
Views: 6,687

Hi all,

sometimes logic totally sucks.

I am making code in C for plotting various graphs, and am making a little routine for inserting ticks on an axis. Ticks have to be "nice" (yes, that's also the word used in the R documentation).

So, let us say the maximum observed value is x=0.234567 and I want ticks evenly dispersed at a distance of dx=0.05 (say from 0.0 and upwards). So, I thought I was clever and calculated the "maximum" tick as
xmax = dx*ceil(x/dx)

You can see one definition of the ceil function here.

So, one way to test it is like this, which will print the actual ticks:

int Test10001(double x, double dx)
    double xmax;
    while (x<=xmax)

When I call that function with arguments 0.234567 and 0.05 it prints:

but it doesn't print 0.25 ?!???:-D:-D:-D:-D

If I add a line like
printf("xmax=%f\n", xmax);

then I get

This is the beauty of C. Sometimes it is all-out warfare with this language and little tasks that should take 2 minutes take 2 days and end up with theory around little endians and data types and ANSI specifications and God knows what else :crying::crying:.

Edit: Category changed; see also this post #1. [Helmut]

Pass or fail!

Complete thread:

UA Flag
 Admin contact
22,557 posts in 4,724 threads, 1,607 registered users;
28 visitors (0 registered, 28 guests [including 10 identified bots]).
Forum time: 09:34 CEST (Europe/Vienna)

The function of genius is not to give new answers, but to pose
new questions which time and mediocrity can resolve.    H.R. Trevor-Roper

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz