floating point

Feb 24, 2012 at 2:00 PM
Edited Feb 24, 2012 at 2:04 PM

[sorry for my Eng]

In some culture settings (Russian e.g.) floating point is comma. The term 

meanval(X,Y,Z) :-
    (Z is ((X + Y) / 2)).
:-meanval(11.4, 12.8, M). 

will cause error "unrecognized input".

For fixing this behavior I use two source code corrections:

Add Priority=1 in file LiteralDouble.cs:

namespace Prolog.Grammar
{
    [Terminal(@"-?[0-9]{1,10}\.[0-9]{1,10}", Priority=1)]
    internal sealed class LiteralDouble : PrologTerminal
    { }
}
Add invariant culture when double is parsing. File Value.cs: 
        public static void Rule(Value lhs, LiteralDouble literal)
        {
            CodeValueDouble codeValueDouble = new CodeValueDouble(double.Parse(literal.Text, System.Globalization.CultureInfo.InvariantCulture.NumberFormat));
 
            lhs.CodeTerm = codeValueDouble;
        }
After those modifications :-meanval(11.4, 12.8, M). is working good: M=12,1 (output format (comma) in Workbench is russian-localized yet).

Is this method correct or not?

Slava.