Bug in QL C - Lattice C?

Anything QL Software or Programming Related.
ohcan_ognara
ROM Dongle
Posts: 3
Joined: Thu Nov 03, 2016 4:10 pm

Bug in QL C - Lattice C?

Postby ohcan_ognara » Sat Jan 12, 2019 6:12 pm

Hello

After 30 years or more I've come back to QL playing with ancient QLC. I'm using the POW() function but it seems I've never been able to obtain correct results. This little program below returns 1.000000 whereas it should return 4.000000.

Is that a bug or do you thing I'm doing something wrong...

Thanks

Code: Select all

#include <mdv1_stdio_h>
#include <mdv1_math_h>

main()
{

   double ov2;

   ov2 = pow(2,2);
   printf("%f\n", ov2);

}


User avatar
XorA
Super Gold Card
Posts: 575
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Bug in QL C - Lattice C?

Postby XorA » Sat Jan 12, 2019 7:14 pm

try pow(2.0,2.0)

pow takes doubles as arguments and you've passed it ints, older compilers don't always promote correctly.


User avatar
NormanDunbar
Super Gold Card
Posts: 660
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Bug in QL C - Lattice C?

Postby NormanDunbar » Sat Jan 12, 2019 7:49 pm

What do you get if you do this instead?

Code: Select all

   ov2 = pow(2.0, 2.0);


Or

Code: Select all

   ov2 = pow((double)2.0, (double)2.0);



Cheers,
Norm.


Why do they put lightning conductors on churches?
If at first you don't succeed, don't take up skydiving!
If you think your job is pointless, remember, there's someone in Germany who fits indicators to BMWs.
ohcan_ognara
ROM Dongle
Posts: 3
Joined: Thu Nov 03, 2016 4:10 pm

Re: Bug in QL C - Lattice C?

Postby ohcan_ognara » Sat Jan 12, 2019 8:53 pm

Thanks Norm and XorA.

Indeed both solutions work. I was a little confused since the very same code worked on Lattice 3.04 (Atari ST). It seems as you stated correctly that Lattice 3.02 (QL) is not able to promote ints to doubles correctly.

Thank you guys!


User avatar
ql_freak
Trump Card
Posts: 174
Joined: Sun Jan 18, 2015 1:29 am

Re: Bug in QL C - Lattice C?

Postby ql_freak » Mon Jan 14, 2019 5:39 pm

Warning: QLC (Lattice C 3.02) has one really horrible bug in stdio.h. When it returns EOF (which must be an int - that was always so, even in K&R C), it returns a char. As char is signed on the 68000, when the character code FF (decimal 255) exists in a file, it is sign extended and EOF (-1) is returned. This makes the stdio functions nearly unusable for binary data. BTW: The first versions of C68 have had the same bug.

Correct behaviour is: Return 0xFF (255) as an int (0x00FF) for the character code 0xFF and -1 as int (0xFFFF) for EOF.

BTW: For your example you should at least get a warning if you change it to:

Code: Select all

#include <mdv1_stdio_h>
#include <mdv1_math_h>

double pow(double, double); /* Lattice C supports function prototypes, albeit not ANSI-C compatible */

main()
{

   double ov2;

   ov2 = pow(2,2);
   printf("%f\n", ov2);

}


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE§() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)

Return to “Software & Programming”

Who is online

Users browsing this forum: No registered users and 3 guests