Lazarus

Free Pascal => Unix => Topic started by: kristakis on August 23, 2018, 04:45:17 am

Title: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: kristakis on August 23, 2018, 04:45:17 am
Hi,

I had an issue with a comparison of two currency values after upgrading from fpc 2.6.4 to 3.0.0. I had a look around but couldn't find anything about it. It could be related to how I'm using Abs() but I thought I'd post it here in case it really is a bug.

Here's my code:
Code: Pascal  [Select][+][-]
  1. program quicktest;
  2. {$MODE OBJFPC}{$H+}
  3. uses
  4.     classes, sysutils, baseunix, crt;
  5. var
  6.     a: currency;
  7.     b: currency;
  8. begin
  9.     a := -6;
  10.     b := 9.6;
  11.     if b < Abs(a) then
  12.         writeln('this is madness!')
  13.     else
  14.         writeln('sanity prevails.');
  15.     // bonus round
  16.     writeln(IntToStr(Length('¥')));
  17.     writeln(IntToStr(Length('$')));
  18. end.
  19.  

When I compile that on fpc 2.6.4 it works and sanity prevails. When I compile it on fpc 3.0.0 there is madness. I have 2.6.4 on Raspbian Jessie and 3.0.0 on Raspbian Stretch but when I copy the 2.6.4 executable over to Stretch it works.

Also I noticed that the Yen symbol has a length of 2 while Dollar is only 1. This happens in 2.6.4 and 3.0.0.

Maybe all these are fixed in 3.0.4, I am investigating how to install that now. If not then I'll flip back to the 2.6.4 environment.

thanks.
kris

Title: Re: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: lucamar on August 23, 2018, 05:24:14 am
I can't help you regarding the problem with abs() but about this:

Also I noticed that the Yen symbol has a length of 2 while Dollar is only 1. This happens in 2.6.4 and 3.0.0.

that's most probably because your source is UTF-8. Unicode places the $ in the ASCII group (Ux32..Ux126), while the yen symbol (as all other monetary symbols) is in a higher code group which means UTF-8 needs more than one byte to code it.

Remember than Length() returns the lenght in bytes of its argument.

-----
Incidentally ... FPC 3.0.0 is (relatively) old; lots of fixes were done up to the latest stable version 3.0.4 --- and even more up to 3.2.0 which is coming Really Soon(tm).
Title: Re: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: Handoko on August 23, 2018, 05:29:14 am
@kristakis

I copied/pasted your code and tested on FPC 3.0.4 Linux, I got correct result: "sanity prevails."
Title: Re: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: balazsszekely on August 23, 2018, 06:16:27 am
Works here too with 3.0.4
Title: Re: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: kristakis on August 23, 2018, 07:01:23 am
@lucamar Thanks for the info, I had the suspicion just after submitting that it might be a unicode thing.

@all Good to hear it's been fixed. I'll need to work on getting 3.0.4 installed on the Pi.

thanks,
kris
Title: Re: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: Thaddy on August 23, 2018, 03:27:47 pm

Maybe all these are fixed in 3.0.4, I am investigating how to install that now. If not then I'll flip back to the 2.6.4 environment.

thanks.
kris
3.0.4 is in stretch-backports
simply add that to /etc/apt/sources.list and use sudo apt-get -t fpc to install (must use -t parameter)
Title: Re: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: valdir.marcos on August 23, 2018, 06:34:13 pm
3.0.4 is in stretch-backports
simply add that to /etc/apt/sources.list and use sudo apt-get -t fpc to install (must use -t parameter)
The complete command is:
sudo apt-get -t stretch-backports fpc

But not so simply, you need to set Apt-Pinning:
Apt-Pinning for Beginners
https://jaqque.sbih.org/kplug/apt-pinning.html
Title: Re: Currency compare different between 2.6.4 and 3.0.0 on Raspian
Post by: Thaddy on August 23, 2018, 09:12:36 pm
But not so simply, you need to set Apt-Pinning:
Apt-Pinning for Beginners
https://jaqque.sbih.org/kplug/apt-pinning.html
I didn't use apt-pinning here. It was not necessary. It's backports, not unstable.
TinyPortal © 2005-2018