Scripts discussion (4)

Discuss and announce AkelPad plugins
  • Author
  • Message
DV
Offline
Posts: 1291
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: Scripts discussion (4)

Post by DV »

Regarding the features of AkelPad's calculators, personally I am very impressed by the CalculatorJS by KDJ.
Take a look at this screenshot that demonstrates how the CalculatorJS deals with variables:

Image

At first, we have a value `x=10` that has been set by means of "Result to X".
Then, we have an inline variable `a=5`.
Finally, the result is an array that uses the current values of both `a` and `x`.
To me, this is simply amazing.

Offline
Posts: 43
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: Scripts discussion (4)

Post by ewild »

DV, of cource, you're right. KDJ's CalculatorJS is great, too.
Definitely, I use it from time to time, when needed (overall, I have five js calculators). But it is, to say... too powerful.
It's a scientific-level calculator with a rich interface. However, there are simpler tasks for which mathCalc fits better, from my point of view.
By the way, mathCalc is only one of them that handles in-text % operations, all the other would return syntax errors there.

DV, incidentally, do you know if there are any hints/tricks/settings on how to get rid of those .99999999999999 in CalculatorJS?

DV
Offline
Posts: 1291
Joined: Thu Nov 16, 2006 11:53 am
Location: Kyiv, Ukraine

Re: Scripts discussion (4)

Post by DV »

ewild wrote: Thu Dec 19, 2024 3:03 pmif there are any hints/tricks/settings on how to get rid of those .99999999999999 in CalculatorJS?
We may try an approach similar to this one (the `format_result` method):
https://github.com/d0vgan/nppexec/blob/ ... .cpp#L1018

Though I can't advise where exactly to do something like that in the CalculatorJS.

Offline
Posts: 5
Joined: Tue Nov 12, 2024 10:28 pm

Re: Scripts discussion (4)

Post by xOleg »

MathCalc -- это просто интерфейс к функции eval() Яваскрипта. Он умеет ровно то же, что и она. И не умеет, кстати, тоже (Например, возводит в степень только через Math.pow()). Единственная идея там -- это способ использования, когда математические расчеты являются просто редактированием текста. Подсмотренно у MathCAD, как я и указал в описании.

Offline
Posts: 43
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: Scripts discussion (4)

Post by ewild »

xOleg wrote: Fri Dec 20, 2024 10:27 am...Единственная идея там...
A good idea makes the difference.
xOleg,
By the way, I have an idea for your MathCalc script:
An option to sum all the numbers within the text/selection with modes a. sum only, b. sum regarding the minus sign before numbers.
It can work out as follows:

Code: Select all

$start=AkelPad.GetSelStart();
$end=AkelPad.GetSelEnd();
if ($start == $end)
AkelPad.SetSel(0,-1);
$text=AkelPad.GetSelText();

// extract numbers off the text/selection and make a sum expression from it
$plus=$text.replace(/[^0-9.]/g,"+").replace(/^[+.0]+(\d)/g,"$1").replace(/(\d)[+.]+$/g,"$1").replace(/\+(0|[.])+/g,"+").replace(/\++/g,"+").replace(/(\d)[.][+]/g,"$1+")
// same as above but retain minus sign before numbers and use it in the expression as such
$math=$text.replace(/[^0-9.-]/g,"+").replace(/^[+-.0]+(\d)/g,"$1").replace(/(\d)[+-.]+$/g,"$1").replace(/\+0+/g,"+").replace(/\-0+/g,"-").replace(/\+[.-]+\+/g,"+").replace(/\++/g,"+").replace(/(\d)[.][+]/g,"$1+")

$text=$text+'\r'+$math+'\r'+$plus+'\r'

AkelPad.ReplaceSel($text);

AkelPad.SetSel($start,$start);
Video illustration:
https://i.imgur.com/4CyGtax.mp4

Here, the example script prepares the expressions, and then MathCalc does the actual maths.

Text for testing:

Code: Select all

Lorem ipsum 000 dolor 111 sit amet,
Nullam ut 222 finibus 333 lectus.
"Praesent 444 eusem 555 lorem."
Fusce 05-09-2024 elementum gravida luctus?
Sed non 2,5 accumsan lorem!
1. Vivamus at mauris mi[1]
2. Duis ac faucibus elit.[2][3]
3. Sed sed 'tempor' diam.
Vivamus tincidunt tristique dolor.[4,5]
Morbi vel 25.25 blandit augue.

Offline
Posts: 5
Joined: Tue Nov 12, 2024 10:28 pm

Re: Scripts discussion (4)

Post by xOleg »

I have an idea for your MathCalc script
Смысл понятен, но для латинницы такого не сделать, поскольку будут отброшены встроенные функции и еще много разных интересных вещей. Например:

{sin(PI/6)} = 0.5

Но, самое главное, что такое изменение противоречило бы самой концепции скрипта как "живых" математических вычислений. Вот небольшая демонстрация, как все работает:

https://youtu.be/oNnZl-bF5E8

Offline
Posts: 43
Joined: Sat Jul 05, 2008 11:30 am
Location: Odesa, Ukraine

Re: Scripts discussion (4)

Post by ewild »

xOleg,
It could be a part of such a live math-in-text flow, too.
That's why I offered it.
From my point of view, it fits MathCalc conception pretty harmonically.
For instance, you're typing 'I bought 5 apples in the morning, and then Maria gifted me 7 more apples in the noon, so now I have' {hitting a magic button, and voila!} 5+7 = 12 {typing further} 'ones!'

OK then, meet mathText.js.
Yet another math script in the collection.
https://akelpad.sourceforge.net/forum/v ... 657#p36657

Offline
Posts: 3234
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Re: Scripts discussion (4)

Post by VladSh »

ewild
Подобный скрипт уже был - SumNumbers.js.
Post Reply