Recent

Author Topic: [SOLVED] TFPExpressionParser : unexpected character in number  (Read 898 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 390
[SOLVED] TFPExpressionParser : unexpected character in number
« on: January 27, 2025, 05:44:26 pm »
Does it understand ** as exponent ?
'+-' is ok ?
.... ?
Or maybe something wrong encoded in string ?


Quote
mathExpression = '-(2*(1.5707963267949*-314.159265358979−1.5707963267949*0−0))+sqr((2*(1.5707963267949*-314.159265358979−1.5707963267949*0−0))**2−4((1.5707963267949**2+1))(0**2−200**2+0**2−2-314.1592653589790+-314.159265358979**2))/2((1.5707963267949**2+1))'
« Last Edit: January 28, 2025, 01:25:59 am by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TFPExpressionParser : unexpected character in number
« Reply #1 on: January 27, 2025, 05:47:07 pm »
https://wiki.freepascal.org/How_To_Use_TFPExpressionParser#Operators
Quote
The expressions discussed above show that standard operators +, -, *, /, <, <=, etc., can be used to setup an expression. Additionally, in recent FPC versions, the operator ^ is available for calculating the power, and mod for the remainder of integer divisions (modulo).
Today is tomorrow's yesterday.

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 390
Re: TFPExpressionParser : unexpected character in number
« Reply #2 on: January 27, 2025, 05:57:28 pm »
replaced all '**' with '^', same result.

Maybe strange questin mark, in message box,  points to some wrong encoded character ?
lazarus 3.2-fpc-3.2.2-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: TFPExpressionParser : unexpected character in number
« Reply #3 on: January 27, 2025, 06:01:58 pm »
Define the expression string explicitly as AnsiString otherwise at least with Laz you can get results that you do not expect.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: TFPExpressionParser : unexpected character in number
« Reply #4 on: January 27, 2025, 06:02:30 pm »
If pasted expression in your original message is from source-editor then replace the minus sign and try again. Do not use the special minus and plus signs but the 'normal' ones.
Today is tomorrow's yesterday.

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: TFPExpressionParser : unexpected character in number
« Reply #5 on: January 27, 2025, 06:09:13 pm »
...−4((1.57...

...))/2((1.570...

...+1))(0**2−...

?

"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

wp

  • Hero Member
  • *****
  • Posts: 13401
Re: TFPExpressionParser : unexpected character in number
« Reply #6 on: January 27, 2025, 06:16:13 pm »
Your minus characters appear a tiny bit longer than what I am used to. Retyped all of them in my formula. Now the parser no longer complains about the wrong encoded character, but fails with the syntax issues in this formula.

Hint: define variables a = 1.5707963267949 and b = 314.159265358979 and use them in writing the expression - it will be much shorter now und much easier to understand.

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 390
Re: TFPExpressionParser : unexpected character in number
« Reply #7 on: January 28, 2025, 01:25:32 am »
Tiny minus sign, hard to se. Solution is to retype that and char left and right of that.
The whole problem originated from copying equation from some web page.
Thanks to all.
« Last Edit: January 28, 2025, 01:27:22 am by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

 

TinyPortal © 2005-2018