├── .gitlab-ci.yml ├── COPYING ├── NEWS ├── README.md ├── data ├── gcalccmd.1 ├── gnome-calculator.1 ├── icons │ └── hicolor │ │ ├── scalable │ │ └── apps │ │ │ ├── org.gnome.Calculator.Devel.svg │ │ │ └── org.gnome.Calculator.svg │ │ └── symbolic │ │ └── apps │ │ └── org.gnome.Calculator-symbolic.svg ├── meson.build ├── org.gnome.Calculator.Source.svg ├── org.gnome.Calculator.desktop.in ├── org.gnome.Calculator.metainfo.xml.in └── org.gnome.calculator.gschema.xml ├── doc └── meson.build ├── gcalc ├── gcalc-assign.vala ├── gcalc-calculator.vala ├── gcalc-constant.vala ├── gcalc-division.vala ├── gcalc-equation-manager.vala ├── gcalc-equation.vala ├── gcalc-error-result.vala ├── gcalc-expression-container.vala ├── gcalc-expression-hash-map.vala ├── gcalc-expression.vala ├── gcalc-function-acos.vala ├── gcalc-function-acosh.vala ├── gcalc-function-asin.vala ├── gcalc-function-asinh.vala ├── gcalc-function-atan.vala ├── gcalc-function-atanh.vala ├── gcalc-function-cos.vala ├── gcalc-function-cosh.vala ├── gcalc-function-exp.vala ├── gcalc-function-log.vala ├── gcalc-function-sin.vala ├── gcalc-function-sinh.vala ├── gcalc-function-sqrt.vala ├── gcalc-function-tan.vala ├── gcalc-function-tanh.vala ├── gcalc-function.vala ├── gcalc-group.vala ├── gcalc-hashable.vala ├── gcalc-math-assign.vala ├── gcalc-math-binary-operator.vala ├── gcalc-math-constant-complex.vala ├── gcalc-math-constant-number.vala ├── gcalc-math-constant-vector.vala ├── gcalc-math-constant.vala ├── gcalc-math-division.vala ├── gcalc-math-equation-manager.vala ├── gcalc-math-equation.vala ├── gcalc-math-error-result.vala ├── gcalc-math-expression.vala ├── gcalc-math-function.vala ├── gcalc-math-group.vala ├── gcalc-math-minus.vala ├── gcalc-math-multiply.vala ├── gcalc-math-operator.vala ├── gcalc-math-parameter.vala ├── gcalc-math-plus.vala ├── gcalc-math-polynomial.vala ├── gcalc-math-pow.vala ├── gcalc-math-result.vala ├── gcalc-math-term.vala ├── gcalc-math-variable.vala ├── gcalc-minus.vala ├── gcalc-multiply.vala ├── gcalc-parameter.vala ├── gcalc-parser.vala ├── gcalc-plus.vala ├── gcalc-polynomial.vala ├── gcalc-pow.vala ├── gcalc-result.vala ├── gcalc-solver.vala ├── gcalc-term.vala ├── gcalc-units.vala ├── gcalc-variable.vala ├── gcalc.deps.in ├── gcalc.pc.in ├── meson.build └── namespace-info.vala.in ├── gci ├── gci-entry-controller.vala ├── gci.deps.in ├── gci.pc.in ├── meson.build └── namespace-info.vala.in ├── gnome-calculator.doap ├── help ├── C │ ├── absolute.page │ ├── base.page │ ├── boolean.page │ ├── complex.page │ ├── conv-base.page │ ├── conv-character.page │ ├── conv-currency.page │ ├── conv-length.page │ ├── conv-time.page │ ├── conv-weight.page │ ├── equation.page │ ├── factorial.page │ ├── factorize.page │ ├── figures │ │ └── org.gnome.Calculator.svg │ ├── financial.page │ ├── functions.page │ ├── history.page │ ├── index.page │ ├── keyboard.page │ ├── legal.xml │ ├── logarithm.page │ ├── mode-programming.page │ ├── modulus.page │ ├── mouse.page │ ├── number-display.page │ ├── percentage.page │ ├── power.page │ ├── rounding.page │ ├── scientific.page │ ├── superscript.page │ ├── trigonometry.page │ └── variables.page ├── LINGUAS ├── ca │ └── ca.po ├── cs │ └── cs.po ├── da │ └── da.po ├── de │ └── de.po ├── el │ └── el.po ├── es │ └── es.po ├── eu │ └── eu.po ├── fi │ └── fi.po ├── fr │ └── fr.po ├── gl │ └── gl.po ├── hu │ └── hu.po ├── id │ └── id.po ├── it │ └── it.po ├── ja │ └── ja.po ├── ko │ └── ko.po ├── lv │ └── lv.po ├── meson.build ├── nl │ └── nl.po ├── oc │ └── oc.po ├── pl │ └── pl.po ├── pt │ └── pt.po ├── pt_BR │ └── pt_BR.po ├── ro │ └── ro.po ├── ru │ └── ru.po ├── sl │ └── sl.po ├── sv │ └── sv.po ├── te │ └── te.po ├── tr │ └── tr.po ├── uk │ └── uk.po ├── zh_CN │ └── zh_CN.po ├── zh_HK │ └── zh_HK.po └── zh_TW │ └── zh_TW.po ├── lib ├── currency-provider.vala ├── currency.vala ├── equation-lexer.vala ├── equation-parser.vala ├── equation.vala ├── financial.vala ├── function-manager.vala ├── math-equation.vala ├── math-function.vala ├── math-variables.vala ├── meson.build ├── mpfr-glue.vala ├── number.vala ├── providers │ ├── boc-provider.vala │ ├── ecb-provider.vala │ ├── imf-provider.vala │ └── unt-provider.vala ├── serializer.vala └── unit.vala ├── libmpfr ├── meson.build └── mpfr-glue.vala ├── m4 └── behave-installed-tests.m4 ├── meson.build ├── meson_options.txt ├── org.gnome.Calculator.Devel.json ├── po ├── LINGUAS ├── POTFILES.in ├── POTFILES.skip ├── ab.po ├── af.po ├── am.po ├── ar.po ├── as.po ├── ast.po ├── az.po ├── be.po ├── be@latin.po ├── bg.po ├── bn.po ├── bn_IN.po ├── bs.po ├── ca.po ├── ca@valencia.po ├── cs.po ├── cy.po ├── da.po ├── de.po ├── dz.po ├── el.po ├── en@shaw.po ├── en_CA.po ├── en_GB.po ├── eo.po ├── es.po ├── et.po ├── eu.po ├── fa.po ├── fi.po ├── fil.po ├── fo.po ├── fr.po ├── fur.po ├── ga.po ├── gd.po ├── gl.po ├── gu.po ├── he.po ├── hi.po ├── hr.po ├── hu.po ├── hy.po ├── id.po ├── it.po ├── ja.po ├── ka.po ├── kab.po ├── kk.po ├── km.po ├── kn.po ├── ko.po ├── ku.po ├── lt.po ├── lv.po ├── mai.po ├── meson.build ├── mg.po ├── mjw.po ├── mk.po ├── ml.po ├── mn.po ├── mr.po ├── ms.po ├── my.po ├── nb.po ├── ne.po ├── nl.po ├── nn.po ├── oc.po ├── or.po ├── pa.po ├── pl.po ├── pt.po ├── pt_BR.po ├── ro.po ├── ru.po ├── rw.po ├── si.po ├── sk.po ├── sl.po ├── sq.po ├── sr.po ├── sr@latin.po ├── sv.po ├── ta.po ├── te.po ├── tg.po ├── th.po ├── tk.po ├── tr.po ├── ug.po ├── uk.po ├── vi.po ├── xh.po ├── zh_CN.po ├── zh_HK.po └── zh_TW.po ├── search-provider ├── meson.build ├── org.gnome.Calculator-search-provider.ini ├── org.gnome.Calculator.SearchProvider.service.in └── search-provider.vala ├── snap └── snapcraft.yaml ├── src ├── buttons-advanced.vala ├── buttons-basic.vala ├── buttons-conversion.vala ├── buttons-financial.vala ├── buttons-programming.vala ├── gcalccmd.vala ├── gnome-calculator.vala ├── math-buttons.vala ├── math-converter.vala ├── math-display.vala ├── math-function-popover.vala ├── math-history.vala ├── math-popover.vala ├── math-preferences.vala ├── math-variable-popover.vala ├── math-window.vala ├── meson.build └── ui │ ├── buttons-advanced.ui │ ├── buttons-basic.ui │ ├── buttons-conversion.ui │ ├── buttons-financial.ui │ ├── buttons-programming.ui │ ├── gnome-calculator.gresource.xml │ ├── history-entry.ui │ ├── history-view.ui │ ├── math-converter.ui │ ├── math-display.ui │ ├── math-function-popover.ui │ ├── math-preferences.ui │ ├── math-shortcuts.ui │ ├── math-variable-popover.ui │ ├── math-window.ui │ ├── style-dark.css │ ├── style-hc.css │ └── style.css ├── tests ├── advanced_mode.feature ├── basic_mode.feature ├── common_steps.py ├── environment.py ├── financial_mode.feature ├── gcalc-parsing.vala ├── gcalc-solving-basic.vala ├── gci-test-entry-controller.ui ├── meson.build ├── programming_mode.feature ├── rms_five.xls ├── steps │ └── steps.py ├── test-currency-providers.vala ├── test-entry-controller.gresource.xml ├── test-equation.vala ├── test-gci-entry-controller.vala ├── test-number.vala └── test-serializer.vala └── vapi ├── config.vapi ├── meson.build ├── mpc.vapi └── mpfr.vapi /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | include: 2 | - project: 'gnome/citemplates' 3 | file: 'flatpak/flatpak_ci_initiative.yml' 4 | - component: gitlab.gnome.org/GNOME/citemplates/release-service@master 5 | inputs: 6 | dist-job-name: "flatpak" 7 | tarball-artifact-path: "${TARBALL_ARTIFACT_PATH}" 8 | 9 | variables: 10 | FLATPAK_MODULE: 'gnome-calculator' 11 | TARBALL_ARTIFACT_PATH: ".flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/meson-dist/${CI_PROJECT_NAME}-${CI_COMMIT_TAG}.tar.xz" 12 | 13 | 14 | flatpak: 15 | variables: 16 | MANIFEST_PATH: "org.gnome.Calculator.Devel.json" 17 | FLATPAK_MODULE: "gnome-calculator" 18 | APP_ID: "org.gnome.Calculator.Devel" 19 | RUNTIME_REPO: "https://nightly.gnome.org/gnome-nightly.flatpakrepo" 20 | BUNDLE: "gnome-calculator-dev.flatpak" 21 | extends: '.flatpak' 22 | 23 | nightly: 24 | extends: '.publish_nightly' 25 | dependencies: ['flatpak'] 26 | needs: ['flatpak'] 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GNOME Calculator [![Build Status](https://gitlab.gnome.org/GNOME/gnome-calculator/badges/master/build.svg)](https://gitlab.gnome.org/GNOME/gnome-calculator/pipelines) 2 | 3 | Calculator is an application that solves mathematical equations and is suitable as a default application in a Desktop environment. 4 | 5 | [![Download on Flathub](https://flathub.org/api/badge?svg&locale=en)](https://flathub.org/apps/details/org.gnome.Calculator) 6 | 7 | ## Useful links 8 | 9 | - Homepage: 10 | - Report issues: 11 | - Donate: 12 | - Translate: 13 | -------------------------------------------------------------------------------- /data/gcalccmd.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 2011 Jean Schurger 2 | .TH GCALCCMD 1 "17 March 2011" 3 | .SH NAME 4 | gcalccmd \- a console calculator 5 | .SH SYNOPSIS 6 | .B gcalccmd 7 | 8 | .SH DESCRIPTION 9 | .B gcalccmd 10 | is the console version of 11 | .B gnome-calculator 12 | the calculator of the GNOME desktop environment. 13 | 14 | .SH SEE ALSO 15 | .B gnome-calculator 16 | .sp 17 | .LP 18 | -------------------------------------------------------------------------------- /data/gnome-calculator.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1987-2008 - Sun Microsystems, Inc. 2 | .TH GNOME-CALCULATOR 1 "7 August 2013" 3 | .SH NAME 4 | gnome-calculator \- a desktop calculator 5 | .SH SYNOPSIS 6 | .B gnome-calculator 7 | [ 8 | .I OPTION 9 | ] ... 10 | .SH DESCRIPTION 11 | .B gnome-calculator 12 | is the official calculator of the GNOME desktop environment. 13 | .SH OPTIONS 14 | .TP 15 | .B \-e, \-\-equation 16 | Start gnome-calculator and display the equation following this option. 17 | .TP 18 | .B \-s, \-\-solve 19 | Solve the equation provided following this option. 20 | .TP 21 | .B \-v, \-\-version 22 | Output version information and exit. 23 | .TP 24 | .B \-h, \-?, \-\-help 25 | Prints the command line options. 26 | .SH SEE ALSO 27 | .PD 0 28 | .TP 18 29 | .B gcalccmd 30 | .sp 31 | .LP 32 | -------------------------------------------------------------------------------- /data/icons/hicolor/symbolic/apps/org.gnome.Calculator-symbolic.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /data/meson.build: -------------------------------------------------------------------------------- 1 | # Icons 2 | scalable_iconsdir = join_paths('icons', 'hicolor', 'scalable', 'apps') 3 | install_data( 4 | join_paths(scalable_iconsdir, '@0@.svg'.format(app_id)), 5 | install_dir: join_paths(get_option('datadir'), scalable_iconsdir) 6 | ) 7 | 8 | symbolic_iconsdir = join_paths('icons', 'hicolor', 'symbolic', 'apps') 9 | install_data( 10 | join_paths(symbolic_iconsdir, 'org.gnome.Calculator-symbolic.svg'), 11 | install_dir: join_paths(get_option('datadir'), symbolic_iconsdir), 12 | rename: '@0@-symbolic.svg'.format(app_id) 13 | ) 14 | 15 | # Desktop file 16 | desktop_file_in_config = configuration_data() 17 | desktop_file_in_config.set('app_id', app_id) 18 | desktop_file_in = configure_file( 19 | input: 'org.gnome.Calculator.desktop.in', 20 | output: '@0@.desktop.in'.format(app_id), 21 | configuration: desktop_file_in_config, 22 | ) 23 | 24 | desktop_file = i18n.merge_file( 25 | input: desktop_file_in, 26 | output: '@0@.desktop'.format(app_id), 27 | type: 'desktop', 28 | po_dir: po_dir, 29 | install: true, 30 | install_dir: join_paths(get_option('datadir'), 'applications') 31 | ) 32 | 33 | # Appdata 34 | appconf = configuration_data() 35 | appconf.set('app_id', app_id) 36 | metainfo_file_in = configure_file( 37 | input: 'org.gnome.Calculator.metainfo.xml.in', 38 | output: '@0@.metainfo.xml.in'.format(app_id), 39 | configuration: appconf, 40 | ) 41 | 42 | metainfo_file = i18n.merge_file( 43 | input: metainfo_file_in, 44 | output: '@0@.metainfo.xml'.format(app_id), 45 | po_dir: po_dir, 46 | install: true, 47 | install_dir: join_paths(get_option('datadir'), 'metainfo') 48 | ) 49 | 50 | # Validate metainfo 51 | appstreamcli = find_program('appstreamcli', required: false) 52 | if (appstreamcli.found()) 53 | test('Validating appdata', 54 | appstreamcli, 55 | args: ['validate', '--no-net', '--explain', metainfo_file], 56 | workdir: meson.current_build_dir() 57 | ) 58 | endif 59 | 60 | # Gschema 61 | install_data('org.gnome.calculator.gschema.xml', 62 | install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas'), 63 | ) 64 | 65 | # Manpage 66 | install_man( 67 | 'gnome-calculator.1', 68 | 'gcalccmd.1' 69 | ) 70 | -------------------------------------------------------------------------------- /data/org.gnome.Calculator.desktop.in: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Calculator 3 | Comment=Perform arithmetic, scientific or financial calculations 4 | # Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! 5 | Keywords=calculation;arithmetic;scientific;financial; 6 | Exec=gnome-calculator 7 | # Translators: Do NOT translate or transliterate this text (this is an icon file name)! 8 | Icon=@app_id@ 9 | Terminal=false 10 | Type=Application 11 | StartupNotify=true 12 | Categories=GNOME;GTK;Utility;Calculator; 13 | X-Purism-FormFactor=Workstation;Mobile; 14 | -------------------------------------------------------------------------------- /doc/meson.build: -------------------------------------------------------------------------------- 1 | valadoc = find_program ('valadoc', required: false) 2 | if valadoc.found() 3 | 4 | if get_option('gcalc') 5 | gtkdoc_outdir = CAMEL_CASE_NAME+'-'+API_VERSION 6 | docsdir = join_paths (get_option ('datadir'), 'devhelp','books') 7 | custom_target ('libgcalc_valadocs', 8 | input : gcalc_sources, 9 | output : CAMEL_CASE_NAME+'-'+API_VERSION, 10 | command : [valadoc, 11 | '--doclet=devhelp', 12 | '--force', 13 | '--package-name='+CAMEL_CASE_NAME+'-'+API_VERSION, 14 | '--package-version='+meson.project_version(), 15 | '--vapidir='+gcalc_sources_dir, 16 | '--vapidir='+gcalc_build_dir, 17 | '--vapidir='+libmpfr_vapi_dir, 18 | '--pkg=glib-2.0', 19 | '--pkg=gio-2.0', 20 | '--pkg=gee-0.8', 21 | '--vapidir='+vapis_dir, 22 | '--pkg=mpc', 23 | '--pkg=mpfr', 24 | '--pkg=mpfrg', 25 | '--directory=@OUTDIR@', 26 | '@INPUT@' 27 | ], 28 | install : true, 29 | install_dir : docsdir, 30 | depends: libgcalc 31 | ) 32 | endif 33 | 34 | if not get_option('disable-ui') and get_option('gci') and get_option('gcalc') 35 | gtkdoc_outdir = GCI_CAMEL_CASE_NAME+'-'+GCI_API_VERSION 36 | docsdir = join_paths (get_option ('datadir'), 'devhelp','books') 37 | 38 | custom_target ('libgci_valadocs', 39 | input : gci_sources, 40 | output : GCI_CAMEL_CASE_NAME+'-'+GCI_API_VERSION, 41 | command : [valadoc, 42 | '--doclet=devhelp', 43 | '--force', 44 | '--package-name='+GCI_CAMEL_CASE_NAME+'-'+GCI_API_VERSION, 45 | '--package-version='+meson.project_version(), 46 | '--vapidir='+gcalc_build_dir, 47 | '--vapidir='+gci_build_dir, 48 | '--pkg=glib-2.0', 49 | '--pkg=gio-2.0', 50 | '--pkg=gee-0.8', 51 | '--vapidir='+vapis_dir, 52 | '--pkg=gcalc-'+API_VERSION, 53 | '--pkg=gtk4', 54 | '--directory=@OUTDIR@', 55 | '@INPUT@' 56 | ], 57 | install : true, 58 | install_dir : docsdir, 59 | depends: libgcalc 60 | ) 61 | endif 62 | 63 | endif 64 | -------------------------------------------------------------------------------- /gcalc/gcalc-assign.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-gassign.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathAssign} 23 | */ 24 | public class GCalc.Assign : Expression, MathOperator, MathBinaryOperator, MathAssign { 25 | internal override string to_string () { 26 | if (expressions.get_n_items () != 2) { 27 | return "Invalid Assigment structure"; 28 | } 29 | var v = expressions.get_item (0) as MathVariable; 30 | if (v == null) { 31 | return "Invalid Assigment structure. No variable is set"; 32 | } 33 | var e = expressions.get_item (1) as MathExpression; 34 | if (e == null) { 35 | return "Invalid Assigment structure. No variable's definition is set"; 36 | } 37 | return v.to_string ()+"="+e.to_string (); 38 | } 39 | internal override MathResult solve () { 40 | MathResult res = null; 41 | try { 42 | res = new Result (evaluate ()); 43 | } catch (GLib.Error e) { 44 | res = new ErrorResult ("Invalid expression in Assignment: %s".printf (e.message)); 45 | } 46 | return res; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /gcalc/gcalc-division.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-division.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathDivision} 23 | */ 24 | public class GCalc.Division : Expression, MathOperator, MathBinaryOperator, MathDivision { 25 | internal override string to_string () { 26 | return "/"; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gcalc/gcalc-equation-manager.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-equation-manager.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathEquationManager} 23 | */ 24 | public class GCalc.EquationManager : Object, MathEquationManager { 25 | ExpressionContainer _equations = new ExpressionContainer (); 26 | ExpressionContainer _functions = new ExpressionContainer (); 27 | internal ExpressionContainer equations { get { return _equations; } } 28 | internal ExpressionContainer functions { get { return _functions; } } 29 | 30 | construct { 31 | // Initialize default Functions 32 | functions.add (new FunctionSqrt ()); 33 | functions.add (new FunctionExp ()); 34 | functions.add (new FunctionLog ()); 35 | functions.add (new FunctionSin ()); 36 | functions.add (new FunctionCos ()); 37 | functions.add (new FunctionTan ()); 38 | functions.add (new FunctionAsin ()); 39 | functions.add (new FunctionAcos ()); 40 | functions.add (new FunctionAtan ()); 41 | functions.add (new FunctionSinh ()); 42 | functions.add (new FunctionCosh ()); 43 | functions.add (new FunctionTanh ()); 44 | functions.add (new FunctionAsinh ()); 45 | functions.add (new FunctionAcosh ()); 46 | functions.add (new FunctionAtanh ()); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /gcalc/gcalc-equation.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-quation.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathEquation} 23 | */ 24 | public class GCalc.Equation : Expression, MathEquation { 25 | ExpressionHashMap _variables = new ExpressionHashMap (); 26 | internal ExpressionHashMap variables { get { return _variables; } } 27 | internal override MathResult solve () { 28 | MathResult res = null; 29 | if (expressions.get_n_items () == 0) { 30 | return new ErrorResult ("No expressions found in equation"); 31 | } 32 | var e = expressions.get_item (0) as MathExpression; 33 | if (e == null) { 34 | res = new ErrorResult ("Invalid expression in equation"); 35 | } else { 36 | res = e.solve (); 37 | } 38 | return res; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /gcalc/gcalc-error-result.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-gerror-result.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathErrorResult} 23 | */ 24 | /** 25 | * An implementation of {@link MathErrorResult} 26 | */ 27 | public class GCalc.ErrorResult : Object, MathResult, MathErrorResult { 28 | private string msg = ""; 29 | private MathExpression _expression; 30 | 31 | public ErrorResult (string msg) { 32 | this.msg = msg; 33 | _expression = new ErrorExpression (); 34 | } 35 | // Result 36 | public MathExpression expression { get { return _expression; } } 37 | public string to_string () { return msg; } 38 | // ErrorResult 39 | public string message { get { return msg; } } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /gcalc/gcalc-expression-container.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-expression-container.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An expression container implementing {@link GLib.ListModel} 23 | */ 24 | public class GCalc.ExpressionContainer : Gee.ArrayList, GLib.ListModel { 25 | public weak MathExpression parent { get; set; } 26 | 27 | // Gee.AbstractCollection 28 | public override bool add (MathExpression exp) { 29 | var r = base.add (exp); 30 | exp.parent = parent; 31 | return r; 32 | } 33 | 34 | public override MathExpression remove_at (int index) { 35 | var r = base.remove_at (index); 36 | if (r != null) { 37 | r.parent = null; 38 | } 39 | return r; 40 | } 41 | 42 | public override bool remove (MathExpression exp) { 43 | var r = base.remove (exp); 44 | if (r) { 45 | exp.parent = null; 46 | } 47 | return r; 48 | } 49 | 50 | // GLib.ListModel 51 | public Object? get_item (uint position) { 52 | return base.@get ((int) position) as Object; 53 | } 54 | 55 | public Type get_item_type () { 56 | return typeof (MathExpression); 57 | } 58 | 59 | public uint get_n_items () { 60 | return size; 61 | } 62 | 63 | public Object? get_object (uint position) { 64 | return get_item (position); 65 | } 66 | 67 | public MathExpression? find (MathExpression exp) { 68 | unowned MathVariable? variable = exp as MathVariable; 69 | if (variable == null) { 70 | return null; 71 | } 72 | foreach (MathExpression e in this) { 73 | if (e is MathVariable && ((MathVariable) e).name == variable.name) { 74 | return e; 75 | } 76 | } 77 | return null; 78 | } 79 | 80 | public MathExpression? find_named (string name) { 81 | foreach (MathExpression e in this) { 82 | if (e is MathVariable && ((MathVariable) e).name == name) { 83 | return e; 84 | } 85 | if (e is MathFunction && ((MathFunction) e).name == name) { 86 | return e; 87 | } 88 | } 89 | return null; 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /gcalc/gcalc-expression-hash-map.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-expression-hash-table.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A hash table using {@link Hashable} objects 23 | */ 24 | public class GCalc.ExpressionHashMap : Gee.HashMap { 25 | public weak MathExpression parent { get; set; } 26 | 27 | public void add (MathExpression exp) 28 | requires (exp is Hashable) 29 | { 30 | @set (((Hashable) exp).hash (), exp); 31 | exp.parent = parent; 32 | } 33 | 34 | public void remove (MathExpression exp) { 35 | unset (((Hashable) exp).hash ()); 36 | } 37 | 38 | public MathExpression? find_named (string name) { 39 | return @get (name.hash ()); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /gcalc/gcalc-expression.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-expresion.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathExpression} 23 | */ 24 | public class GCalc.Expression : Object, MathExpression { 25 | ExpressionContainer exps = new ExpressionContainer (); 26 | construct { 27 | exps.parent = this; 28 | } 29 | // Expression 30 | internal weak MathExpression parent { get; set; } 31 | internal ExpressionContainer expressions { get { return exps; } } 32 | internal virtual string to_string () { 33 | string s = ""; 34 | foreach (MathExpression e in expressions) { 35 | s += e.to_string (); 36 | } 37 | return s; 38 | } 39 | internal virtual MathResult solve () { 40 | return new ErrorResult ("Invalid expression"); 41 | } 42 | } 43 | 44 | /** 45 | * Represent an expression in error condition 46 | */ 47 | public class GCalc.ErrorExpression : Expression {} 48 | 49 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-acos.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-acos.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate arc cosine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionAcos : Function { 25 | 26 | construct { 27 | name = "acos"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.acos (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-acosh.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-acosh.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate arc hyperbolic cosine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionAcosh : Function { 25 | 26 | construct { 27 | name = "acosh"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.acosh (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-asin.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-asin.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate arc sine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionAsin : Function { 25 | 26 | construct { 27 | name = "asin"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.asin (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-asinh.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-asinh.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate arc hyperbolic sine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionAsinh : Function { 25 | 26 | construct { 27 | name = "asinh"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.asinh (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-atan.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-atan.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate arc tangent of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionAtan : Function { 25 | 26 | construct { 27 | name = "atan"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.atan (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-atanh.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-atanh.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate arc hyperbolic tangent of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionAtanh : Function { 25 | 26 | construct { 27 | name = "atanh"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.atanh (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-cos.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-cos.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate cosine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionCos : Function { 25 | 26 | construct { 27 | name = "cos"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.cos (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-cosh.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-cosh.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate hyperbolic cosine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionCosh : Function { 25 | 26 | construct { 27 | name = "cosh"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.cosh (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-exp.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-exp.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | 22 | /** 23 | * Function to calculate inverse of logarithm of a {@link MathConstant} 24 | */ 25 | public class GCalc.FunctionExp : Function { 26 | 27 | construct { 28 | name = "exp"; 29 | n_params = 1; 30 | param_types.add (new Constant ()); 31 | } 32 | 33 | internal override MathExpression evaluate () throws GLib.Error 34 | { 35 | verify_params (); 36 | Constant c = null; 37 | var exp = expressions.get_item (0) as MathExpression; 38 | if (exp == null) { 39 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 40 | } 41 | var ev = exp.solve (); 42 | if (ev is ErrorResult) { 43 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 44 | } 45 | if (ev is MathResult) { 46 | c = ((MathResult) ev).expression as Constant; 47 | } 48 | if (c == null) { 49 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 50 | } 51 | var p1 = MPC.Complex (1000); 52 | p1.set (c.get_complex ()); 53 | var res = MPC.Complex (1000); 54 | res.exp (p1); 55 | var nc = new Constant.internal_complex (res); 56 | return nc as MathExpression; 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-log.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-log.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate logarithm of a {@link MathConstant} 23 | */ 24 | public class GCalc.FunctionLog : Function { 25 | 26 | construct { 27 | name = "log"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.log (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-sin.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-sin.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate sine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionSin : Function { 25 | 26 | construct { 27 | name = "sin"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.sin (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-sinh.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-sinh.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate hyperbolic sine of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionSinh : Function { 25 | 26 | construct { 27 | name = "sinh"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.sinh (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-sqrt.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-sqrt.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate square root of a {@link MathConstant} 23 | */ 24 | public class GCalc.FunctionSqrt : Function { 25 | 26 | construct { 27 | name = "sqrt"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.sqrt (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-tan.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-tan.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate tangent of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionTan : Function { 25 | 26 | construct { 27 | name = "tan"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR (_("Invalid parameter type. Expected %s"), typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression: %s"), ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR (_("Invalid expression in result")); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.tan (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function-tanh.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function-tanh.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Function to calculate hyperbolic tangent of a {@link MathConstant} in radians 23 | */ 24 | public class GCalc.FunctionTanh : Function { 25 | 26 | construct { 27 | name = "tanh"; 28 | n_params = 1; 29 | param_types.add (new Constant ()); 30 | } 31 | 32 | internal override MathExpression evaluate () throws GLib.Error 33 | { 34 | verify_params (); 35 | Constant c = null; 36 | var exp = expressions.get_item (0) as MathExpression; 37 | if (exp == null) { 38 | throw new FunctionError.INVOCATION_ERROR ("Invalid parameter type. Expected %s", typeof(MathExpression).name ()); 39 | } 40 | var ev = exp.solve (); 41 | if (ev is ErrorResult) { 42 | throw new FunctionError.INVOCATION_ERROR ("Invalid expression: %s", ((ErrorResult) ev).message); 43 | } 44 | if (ev is MathResult) { 45 | c = ((MathResult) ev).expression as Constant; 46 | } 47 | if (c == null) { 48 | throw new FunctionError.INVOCATION_ERROR ("Invalid expression in result"); 49 | } 50 | var p1 = MPC.Complex (1000); 51 | p1.set (c.get_complex ()); 52 | var res = MPC.Complex (1000); 53 | res.tanh (p1); 54 | var nc = new Constant.internal_complex (res); 55 | return nc as MathExpression; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /gcalc/gcalc-function.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-function.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathFunction} 23 | */ 24 | public class GCalc.Function : Expression, MathFunction, Hashable { 25 | ExpressionContainer _param_types = new ExpressionContainer (); 26 | 27 | internal ExpressionContainer param_types { get { return _param_types; } } 28 | public uint n_params { get; construct set; } 29 | public string name { get; construct set; } 30 | internal bool closed { get; set; } 31 | 32 | construct { 33 | name = "NoName"; 34 | } 35 | public Function.with_name (string name, int nparams) { 36 | this.name = name; 37 | n_params = nparams; 38 | } 39 | internal override string to_string () { 40 | string s = name + "("; 41 | for (uint i = 0; i < expressions.get_n_items (); i++) { 42 | var e = expressions.get_item (i) as MathExpression; 43 | if (e == null) { 44 | continue; 45 | } 46 | s += e.to_string (); 47 | if (i + 1 < expressions.get_n_items ()) { 48 | s += ","; 49 | } 50 | } 51 | s += ")"; 52 | return s; 53 | } 54 | 55 | internal virtual MathExpression evaluate () throws GLib.Error { 56 | return new ErrorExpression (); 57 | } 58 | // Hashable 59 | internal uint hash () { 60 | return name.hash (); 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /gcalc/gcalc-group.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-ggroup.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathGroup} 23 | */ 24 | public class GCalc.Group : Expression, MathGroup { 25 | internal MathGroup.Level level { get; set; } 26 | internal bool closed { get; set; } 27 | internal override string to_string () { 28 | string s = ""; 29 | switch (level) { 30 | case ONE: 31 | s = "("; 32 | break; 33 | case TWO: 34 | s = "["; 35 | break; 36 | case THREE: 37 | s = "{"; 38 | break; 39 | } 40 | foreach (MathExpression e in expressions) { 41 | s += e.to_string (); 42 | } 43 | switch (level) { 44 | case ONE: 45 | s += ")"; 46 | break; 47 | case TWO: 48 | s += "]"; 49 | break; 50 | case THREE: 51 | s += "}"; 52 | break; 53 | } 54 | return s; 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /gcalc/gcalc-hashable.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-hashable.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * Implemented by objects able to produce a hash. 23 | * 24 | * Returned value can be used in hash tables, for example. 25 | */ 26 | public interface GCalc.Hashable : Object { 27 | /** 28 | * Calculates the hash for this 29 | */ 30 | public abstract uint hash (); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-assign.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-assign.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An assing operator in a math expression 23 | */ 24 | public interface GCalc.MathAssign : Object, MathExpression, MathOperator, MathBinaryOperator { 25 | /** 26 | * Evaluates the assign an returns a {@link MathExpression} as a result 27 | */ 28 | public MathExpression evaluate () throws GLib.Error { 29 | if (expressions.get_n_items () != 2) { 30 | throw new AssigError.INVALID_STRUCTURE_ERROR (_("Invalid number of expressions in assign")); 31 | } 32 | var v = expressions.get_item (0) as MathVariable; 33 | if (v == null) { 34 | throw new AssigError.INVALID_STRUCTURE_ERROR (_("Invalid variable object in assign")); 35 | } 36 | var p = expressions.get_item (1) as MathPolynomial; 37 | if (p == null) { 38 | throw new AssigError.INVALID_STRUCTURE_ERROR (_("Invalid polynomial object in assign")); 39 | } 40 | var ca = p.evaluate () as MathConstant; 41 | if (ca == null) { 42 | throw new AssigError.INVALID_STRUCTURE_ERROR (_("Invalid polynomial evaluation in assign; should a constant no Variable update was done")); 43 | } 44 | v.@value = ca; 45 | return v.@value; 46 | } 47 | } 48 | 49 | public errordomain GCalc.AssigError { 50 | INVALID_STRUCTURE_ERROR 51 | } 52 | 53 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-binary-operator.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-binary-operator.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An operator for two members in a math expression 23 | */ 24 | public interface GCalc.MathBinaryOperator : Object, MathExpression, MathOperator {} 25 | 26 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-constant-complex.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-constant-complex.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A constant as a complex number with real and imaginary parts 23 | */ 24 | public interface GCalc.MathConstantComplex : Object, MathExpression, MathConstant { 25 | /** 26 | * Returns the real part of the complex number 27 | */ 28 | public abstract double real (); 29 | /** 30 | * Returns the imaginary part of the complex number 31 | */ 32 | public abstract double imag (); 33 | /** 34 | * Set the complex number to zero 35 | */ 36 | public abstract void zero (); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-constant-number.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-constant-number.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A constant number value with a double precision number 23 | */ 24 | public interface GCalc.MathConstantNumber : Object, MathExpression, MathConstant { 25 | /** 26 | * Returns the value 27 | */ 28 | public abstract double @value (); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-constant-vector.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-constant-vector.vala 2 | * 3 | * Copyright (C) 2022 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A constant as a complex number with real and imaginary parts 23 | */ 24 | public interface GCalc.MathConstantVector : Object, MathExpression, MathConstant { 25 | /** 26 | * Vector's magnitud 27 | */ 28 | public abstract MathConstant mag (); 29 | /** 30 | * Vector's angle in radians 31 | */ 32 | public abstract MathConstant ang (); 33 | /** 34 | * Magnitud on x axis 35 | */ 36 | public abstract MathConstant x (); 37 | /** 38 | * Magnitud on y axis 39 | */ 40 | public abstract MathConstant y (); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-constant.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-constant.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A constant value in a math expression. 23 | */ 24 | public interface GCalc.MathConstant : Object, MathExpression { 25 | /** 26 | * Add this value with another and returns 27 | * the result 28 | */ 29 | public abstract MathConstant add (MathConstant c); 30 | /** 31 | * Subtract another from this value and returns 32 | * the result 33 | */ 34 | public abstract MathConstant subtract (MathConstant c); 35 | /** 36 | * Multipy another with this value and returns 37 | * the result 38 | */ 39 | public abstract MathConstant multiply (MathConstant c); 40 | /** 41 | * Divide this value as numerator with another as denominator 42 | * and returns the result 43 | */ 44 | public abstract MathConstant divide (MathConstant c); 45 | /** 46 | * Changes the direction of the value and returns 47 | * the result 48 | */ 49 | public abstract MathConstant neg (); 50 | /** 51 | * Pows this value using another and returns 52 | * the result 53 | */ 54 | public abstract MathConstant pow (MathConstant c); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-division.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-division.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A division operator in a math expression 23 | */ 24 | public interface GCalc.MathDivision : Object, MathExpression, MathOperator, MathBinaryOperator {} 25 | 26 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-equation.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-equation.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A math equation with multiple terms 23 | */ 24 | public interface GCalc.MathEquation : Object, MathExpression { 25 | /** 26 | * Set of variables present in the equation expression 27 | */ 28 | public abstract ExpressionHashMap variables { get; } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-error-result.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-error-result.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A kind of result returned when there was an error in a solving operation 23 | */ 24 | public interface GCalc.MathErrorResult : Object, MathResult { 25 | public abstract string message { get; } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-expression.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-expresion.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A part of a math equation 23 | */ 24 | public interface GCalc.MathExpression : Object { 25 | /** 26 | * Parent of the expression 27 | */ 28 | public abstract weak MathExpression parent { get; set; } 29 | /** 30 | * Child expressions 31 | */ 32 | public abstract ExpressionContainer expressions { get; } 33 | /** 34 | * Creates a string representation of the expression 35 | */ 36 | public abstract string to_string (); 37 | /** 38 | * Solves the expression and returning a {@link MathResult} 39 | */ 40 | public abstract MathResult solve (); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-function.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-function.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A Function as part of a {@link MathExpression} 23 | */ 24 | public interface GCalc.MathFunction : Object, MathExpression { 25 | /** 26 | * Parameters used by the function, objects representing 27 | * the expected types. See {@link verify_params} 28 | */ 29 | public abstract ExpressionContainer param_types { get; } 30 | /** 31 | * Function's name 32 | */ 33 | public abstract string name { get; construct set; } 34 | /** 35 | * Number of parameters required by this function 36 | */ 37 | public abstract uint n_params { get; construct set; } 38 | /** 39 | * A condition used while parsing, as a flag when the function 40 | * has been closed or finished and no more parameters should 41 | * be parsed. 42 | */ 43 | public abstract bool closed { get; set; } 44 | /** 45 | * Evaluate the function returning a resulting {@link MathExpression}. 46 | * 47 | * In some cases return is a {@link MathConstant} 48 | */ 49 | public abstract MathExpression evaluate () throws GLib.Error; 50 | /** 51 | * Check the paratemeters given to the function agains {@link param_types} 52 | * and number of parameters using {@link n_params} 53 | */ 54 | public virtual bool verify_params () throws GLib.Error { 55 | if (expressions.get_n_items () != n_params) { 56 | throw new FunctionError.INVALID_PARAMETERS_ERROR (_("Invalid number of parameters. Required %u, provided: %u"), 57 | n_params, expressions.get_n_items ()); 58 | } 59 | return true; 60 | } 61 | } 62 | 63 | public errordomain GCalc.FunctionError { 64 | INVALID_PARAMETERS_ERROR, 65 | INVOCATION_ERROR 66 | } 67 | 68 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-group.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-group.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A grouping math expression like parentesis 23 | */ 24 | public interface GCalc.MathGroup : Object, MathExpression { 25 | public enum Level { 26 | ONE, 27 | TWO, 28 | THREE 29 | } 30 | public abstract Level level { get; set; } 31 | public abstract bool closed { get; set; } 32 | public virtual MathExpression evaluate () throws GLib.Error { 33 | if (expressions.get_n_items () == 0) { 34 | throw new GroupError.INVALID_POLYNOMIAL (_("No internal polynomial in group")); 35 | } 36 | var e = expressions.get_item (0) as MathPolynomial; 37 | if (e == null) { 38 | throw new GroupError.INVALID_POLYNOMIAL (_("Invalid internal polynomial in group")); 39 | } 40 | return e.evaluate (); 41 | } 42 | } 43 | 44 | public errordomain GCalc.GroupError { 45 | INVALID_POLYNOMIAL, 46 | INVALID_INTERNAL_TERM, 47 | } 48 | 49 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-minus.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-minus.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A minus operator in a math expression 23 | */ 24 | public interface GCalc.MathMinus : Object, MathExpression, MathOperator, MathBinaryOperator {} 25 | 26 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-multiply.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-multiply.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A multiply operator in a math expression 23 | */ 24 | public interface GCalc.MathMultiply : Object, MathExpression, MathOperator, MathBinaryOperator {} 25 | 26 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-operator.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-operator.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An operator in a math expression 23 | */ 24 | public interface GCalc.MathOperator : Object, MathExpression {} 25 | 26 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-parameter.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-parameter.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A parameter is a {@link MathVariable} holding a value, that is not 23 | * expected to be resolved as part of an {@link MathExpression} evaluation, 24 | * but by asigning its value. 25 | * 26 | * Currently the value will be converted to a {@link MathConstant} if possible. 27 | */ 28 | public interface GCalc.MathParameter : Object, MathExpression, MathVariable { 29 | public abstract void set_value (GLib.Value? val) throws GLib.Error; 30 | public abstract GLib.Value? get_value (); 31 | } 32 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-plus.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-plus.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A plus operator in a math expression 23 | */ 24 | public interface GCalc.MathPlus : Object, MathExpression, MathOperator, MathBinaryOperator {} 25 | 26 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-polynomial.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-polynomial.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A multiple expressions in a math expression 23 | */ 24 | public interface GCalc.MathPolynomial : Object, MathExpression { 25 | public virtual MathExpression evaluate () throws GLib.Error { 26 | MathTerm current = null; 27 | MathExpression res = null; 28 | for (uint i = 0; i < expressions.get_n_items (); i++) { 29 | var e = expressions.get_item (i) as MathTerm; 30 | if (e == null) { 31 | continue; 32 | } 33 | if (current == null) { 34 | current = (MathTerm) e; 35 | if (i+1 < expressions.get_n_items ()) { 36 | continue; 37 | } 38 | var er = ((MathTerm) e).evaluate (); 39 | if (res == null) { 40 | res = er; 41 | break; 42 | } 43 | if (res is MathConstant && er is MathConstant) { 44 | res = ((MathConstant) res).add ((MathConstant) er); 45 | break; 46 | } 47 | } 48 | var re = current.add ((MathTerm) e); 49 | current = null; 50 | if (res == null) { 51 | res = re; 52 | } else if (res is MathConstant && re is MathConstant) { 53 | res = ((MathConstant) res).add ((MathConstant) re); 54 | } 55 | if (res != null) { 56 | } 57 | } 58 | if (res == null) { 59 | return new ErrorExpression (); 60 | } 61 | return res; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-pow.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-pow.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A pow operator in a math expression 23 | */ 24 | public interface GCalc.MathPow : Object, MathExpression, MathOperator {} 25 | 26 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-result.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-result.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A result of a calculation when the expression is solved 23 | */ 24 | public interface GCalc.MathResult : Object { 25 | public abstract string to_string (); 26 | public abstract MathExpression expression { get; } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /gcalc/gcalc-math-variable.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-math-variable.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A variable that can be evaluated from an {@link MathExpression} 23 | */ 24 | public interface GCalc.MathVariable : Object, MathExpression { 25 | public abstract string name { get; construct set; } 26 | public abstract MathConstant @value { get; set; } 27 | public abstract MathVariable bind { get; set; } 28 | public virtual bool binded { get { return bind != null; } } 29 | 30 | public virtual MathExpression evaluate () throws GLib.Error { 31 | if (bind != null) { 32 | return bind.evaluate (); 33 | } 34 | if (this is MathParameter) { 35 | if (@value == null) { 36 | return new Constant.@double (0.0); 37 | } 38 | return @value; 39 | } 40 | if (parent == null) { 41 | throw new VariableError.INVALID_PARENT (_("Can't access to MathVariable's expression definition. Invalid parent. Expected Assign operator")); 42 | } 43 | if (parent.expressions.get_n_items () != 2) { 44 | throw new VariableError.INVALID_EXPRESSION_DEFINITION (_("Can't access to MathVariable's expression definition. Expression not found")); 45 | } 46 | var e = parent.expressions.get_item (1) as MathPolynomial; 47 | if (e == null) { 48 | throw new VariableError.INVALID_EXPRESSION_DEFINITION (_("Can't access to MathVariable's expression definition. Unexpected object type")); 49 | } 50 | var exp = e.evaluate () as MathConstant; 51 | if (exp == null) { 52 | throw new VariableError.EVALUATION_FAIL (_("MathVariable evaluation fail. MathVariable's value not updated")); 53 | } 54 | @value = exp; 55 | return exp; 56 | } 57 | } 58 | 59 | public errordomain GCalc.VariableError { 60 | INVALID_PARENT, 61 | INVALID_EXPRESSION_DEFINITION, 62 | EVALUATION_FAIL 63 | } 64 | 65 | -------------------------------------------------------------------------------- /gcalc/gcalc-minus.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-minus.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathMinus} 23 | */ 24 | public class GCalc.Minus : Expression, MathOperator, MathBinaryOperator, MathMinus { 25 | internal override string to_string () { 26 | return "-"; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gcalc/gcalc-multiply.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-multiply.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathMultiply} 23 | */ 24 | public class GCalc.Multiply : Expression, MathOperator, MathBinaryOperator, MathMultiply { 25 | internal override string to_string () { 26 | return "*"; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gcalc/gcalc-parameter.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-gparameter.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathParameter} 23 | */ 24 | public class GCalc.Parameter : GCalc.Variable, MathParameter { 25 | 26 | public Parameter (string name) { 27 | base (name); 28 | } 29 | 30 | internal void set_value (GLib.Value? val) throws GLib.Error { 31 | if (val == null) { 32 | @value = null; 33 | return; 34 | } 35 | MathConstant c = new Constant.integer (0); 36 | if (val.holds (GLib.Type.INT)) { 37 | c = new Constant.integer ((int) val); 38 | } else if (val.holds (GLib.Type.DOUBLE)) { 39 | c = new Constant.@double ((double) val); 40 | } else if (val.holds (GLib.Type.FLOAT)) { 41 | c = new Constant.@double ((double) ((float) val)); 42 | } else if (val.type ().is_a (typeof (GCalc.MathConstant))) { 43 | c = (GCalc.MathConstant) ((Object) val); 44 | } 45 | @value = c; 46 | } 47 | 48 | internal GLib.Value? get_value () { 49 | if (@value == null) { 50 | return null; 51 | } 52 | var v = GLib.Value (typeof (GCalc.MathConstant)); 53 | v = @value; 54 | return v; 55 | } 56 | // Expression 57 | internal override string to_string () { 58 | if (@value == null) { 59 | return "$"+name; 60 | } 61 | return @value.to_string (); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /gcalc/gcalc-plus.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-plus.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathPlus} 23 | */ 24 | public class GCalc.Plus : Expression, MathOperator, MathBinaryOperator, MathPlus { 25 | internal override string to_string () { 26 | return "+"; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gcalc/gcalc-polynomial.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-polynomial.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathPolynomial} 23 | */ 24 | public class GCalc.Polynomial : Expression, MathPolynomial { 25 | internal override MathResult solve () { 26 | MathResult res = null; 27 | try { 28 | var e = evaluate (); 29 | res = new Result (e) as MathResult; 30 | } catch (GLib.Error err) { 31 | res = new ErrorResult ("Polynomial solving fails: %s".printf (err.message)); 32 | } 33 | return res; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /gcalc/gcalc-pow.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-pow.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathPow} 23 | */ 24 | public class GCalc.Pow : Expression, MathOperator, MathPow { 25 | internal override string to_string () { 26 | return "^"; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /gcalc/gcalc-result.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-result.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathResult} 23 | */ 24 | public class GCalc.Result : Object, MathResult { 25 | private MathExpression _expression; 26 | public Result (MathExpression exp) { 27 | _expression = exp; 28 | } 29 | // Result 30 | internal string to_string () { 31 | return expression.to_string (); 32 | } 33 | internal MathExpression expression { get { return _expression; } } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /gcalc/gcalc-solver.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-solver.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | using GCalc; 22 | /** 23 | * Math expression solver. 24 | * 25 | * Add any required equations to {@link equation_manager} or use {@link add_expression}, 26 | * then {@link solve} will add a new equation and returns the resulting 27 | * {@link MathResult}. 28 | * {{{ 29 | * var s = new Solver (); 30 | * s.add ("x=3*5"); 31 | * var res = s.solve ("2*x+7*x^2"); 32 | * var c = (MathConstant) res; 33 | * // Result will be 1605 34 | * stdout.printf ("%g", c.real ()); 35 | * }}} 36 | */ 37 | public class GCalc.Solver : Object { 38 | /** 39 | * An equation manager using to solve a given expression 40 | */ 41 | public MathEquationManager equation_manager { get; set; } 42 | 43 | construct { 44 | equation_manager = new EquationManager (); 45 | } 46 | 47 | /** 48 | * Add an equation to {@link equation_manager} 49 | */ 50 | public void add_expression (string exp) throws GLib.Error { 51 | var p = new Parser (); 52 | p.parse (exp, equation_manager); 53 | } 54 | /** 55 | * Add an equation to {@link equation_manager} and solves it 56 | */ 57 | public MathResult solve (string str) throws GLib.Error { 58 | var p = new Parser (); 59 | MathResult res; 60 | try { 61 | p.parse (str, equation_manager); 62 | if (equation_manager.equations.get_n_items () == 0) { 63 | return new ErrorResult (_("No equations found after parsing")); 64 | } 65 | var eq = equation_manager.equations.get_item (0) as MathEquation; 66 | if (eq == null) { 67 | return new ErrorResult (_("No equations found after parsing")); 68 | } 69 | res = eq.solve (); 70 | } catch (GLib.Error e) { 71 | res = new ErrorResult (_("Solving fails: %s").printf (e.message)); 72 | } 73 | return res; 74 | } 75 | } 76 | 77 | public errordomain GCalc.SolverError { 78 | EXPRESSION_ERROR 79 | } 80 | -------------------------------------------------------------------------------- /gcalc/gcalc-term.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-term.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathTerm} 23 | */ 24 | public class GCalc.Term : Expression, MathTerm { 25 | internal override MathResult solve () { 26 | MathResult res = null; 27 | try { 28 | var e = evaluate (); 29 | res = new Result (e) as MathResult; 30 | } catch (GLib.Error err) { 31 | res = new ErrorResult ("Term evaluation fails: %s".printf (err.message)); 32 | } 33 | return res; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /gcalc/gcalc-units.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-units.vala 2 | * 3 | * Copyright (C) 2022 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | 22 | public enum GCalc.AngleUnit 23 | { 24 | RADIANS, 25 | DEGREES, 26 | GRADIANS 27 | } 28 | 29 | public class GCalc.UnitConverter : GLib.Object { 30 | public static MathConstant angle (MathConstant c, AngleUnit ori, AngleUnit dst) { 31 | Constant rc = new Constant.assign (c); 32 | if (ori == dst) { 33 | return rc; 34 | } 35 | 36 | var pi = Calculator.pi (); 37 | if (Calculator.gt (rc, pi.multiply (new Constant.@double (2.0)))) { 38 | var t = rc.divide (pi); 39 | rc = (Constant) rc.subtract (pi.multiply (t)); 40 | } 41 | 42 | 43 | if (ori == AngleUnit.DEGREES && dst == AngleUnit.RADIANS) { 44 | var d = new Constant.@double (180.0); 45 | var g = pi.divide (d); 46 | return rc.multiply (g); 47 | } 48 | 49 | if (ori == AngleUnit.GRADIANS && dst == AngleUnit.RADIANS) { 50 | var d = new Constant.@double (400.0); 51 | var grd = pi.divide (d); 52 | return rc.multiply (grd); 53 | } 54 | 55 | if (ori == AngleUnit.DEGREES && dst == AngleUnit.GRADIANS) { 56 | var d = new Constant.@double (9.0); 57 | var g = new Constant.@double (10.0); 58 | var grd = g.divide (d); 59 | return rc.multiply (grd); 60 | } 61 | 62 | if (ori == AngleUnit.GRADIANS && dst == AngleUnit.DEGREES) { 63 | var d = new Constant.@double (9.0); 64 | var g = new Constant.@double (10.0); 65 | var dg = d.divide (g); 66 | return rc.multiply (dg); 67 | } 68 | 69 | return rc; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /gcalc/gcalc-variable.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-variable.vala 2 | * 3 | * Copyright (C) 2018 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * An implementation of {@link MathVariable} 23 | */ 24 | public class GCalc.Variable : Expression, MathVariable, Hashable { 25 | 26 | public string name { get; construct set; } 27 | internal MathConstant value { get; set; } 28 | internal MathVariable bind { get; set; } 29 | 30 | construct { 31 | _value = null; 32 | } 33 | internal Variable (string name) { 34 | this.name = name; 35 | } 36 | // Expression 37 | internal override string to_string () { 38 | return name; 39 | } 40 | // Hashable 41 | internal uint hash () { 42 | return name.hash (); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /gcalc/gcalc.deps.in: -------------------------------------------------------------------------------- 1 | gio-2.0 2 | gee-0.8 3 | -------------------------------------------------------------------------------- /gcalc/gcalc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=${prefix} 3 | libdir=@libdir@ 4 | datadir=@prefix@/share 5 | includedir=@prefix@/include 6 | 7 | Name: libgcalc 8 | Description: GNOME Calculator Libray 9 | URL: https://apps.gnome.org/Calculator 10 | Version: @PROJECT_VERSION@ 11 | Requires.private: gio-2.0 >= 2.50 gee-0.8 >= 0.20 12 | Libs: -L${libdir} -lgcalc-@API_VERSION@ 13 | Cflags: -I${includedir}/gcalc-@API_VERSION@ 14 | -------------------------------------------------------------------------------- /gcalc/namespace-info.vala.in: -------------------------------------------------------------------------------- 1 | /* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */ 2 | /* Attr.vala 3 | * 4 | * Copyright (C) 2018 Daniel Espinosa 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * Authors: 21 | * Daniel Espinosa 22 | */ 23 | [CCode (gir_namespace = "GCalc", gir_version = "@API_VERSION@", cheader_filename = "gcalc/@PROJECT_NAME@.h")] 24 | namespace GCalc {} 25 | -------------------------------------------------------------------------------- /gci/gci-entry-controller.vala: -------------------------------------------------------------------------------- 1 | /* gcalc-entry-controler.vala 2 | * 3 | * Copyright (C) 2019 Daniel Espinosa 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, see . 17 | * 18 | * Authors: 19 | * Daniel Espinosa 20 | */ 21 | /** 22 | * A {@link Gtk.Entry} controler to provide calculator services 23 | * 24 | * Setup a {@link Gtk.Entry} to response when the user hits the 25 | * enter key or click the secondary icon, to evaluate the math 26 | * expression and substitude the result as the new content text 27 | * of the {@link Gtk.Entry}. 28 | * 29 | * The math expression should start with the equal sign "=", in 30 | * order to execute the math expression evaluation. 31 | * 32 | * If the expression is not a valid one, like using undefined 33 | * variables, the new text is empty. 34 | */ 35 | public class GCi.EntryController : Object { 36 | Gtk.Entry _entry; 37 | public Gtk.Entry entry { 38 | get { 39 | return _entry; 40 | } 41 | set { 42 | _entry = value; 43 | setup (); 44 | } 45 | } 46 | public EntryController.for_entry (Gtk.Entry entry) { 47 | this.entry = entry; 48 | setup (); 49 | } 50 | internal void setup () { 51 | if (entry == null) { 52 | warning ("No entry was set"); 53 | } 54 | entry.secondary_icon_name = "accessories-calculator"; 55 | entry.secondary_icon_activatable = true; 56 | entry.secondary_icon_sensitive = true; 57 | entry.activate.connect (()=>{ 58 | if (!entry.text.has_prefix ("=")) { 59 | return; 60 | } 61 | calculate (); 62 | }); 63 | entry.icon_press.connect ((pos, ev)=>{ 64 | if (!entry.text.has_prefix ("=")) { 65 | return; 66 | } 67 | calculate (); 68 | }); 69 | } 70 | 71 | internal void calculate () { 72 | var s = new GCalc.Solver (); 73 | string str = entry.text.replace ("=", ""); 74 | try { 75 | var r = s.solve (str); 76 | if (r is GCalc.MathResult) { 77 | entry.text = r.expression.to_string (); 78 | } 79 | } catch (GLib.Error e) { 80 | warning ("Math Expression evaluation error: %s", e.message); 81 | } 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /gci/gci.deps.in: -------------------------------------------------------------------------------- 1 | gcalc-2 2 | gtk4 3 | -------------------------------------------------------------------------------- /gci/gci.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=${prefix} 3 | libdir=@libdir@ 4 | datadir=@prefix@/share 5 | includedir=@prefix@/include 6 | 7 | Name: libgcalc 8 | Description: GNOME Calculator Library GTK Interface 9 | URL: https://apps.gnome.org/Calculator 10 | Version: @PROJECT_VERSION@ 11 | Requires.private: gcalc-2 >= 3.34 gtk4 >= 4.4.1 12 | Libs: -L${libdir} -lgci-@API_VERSION@ 13 | Cflags: -I${includedir}/gci-@API_VERSION@ 14 | -------------------------------------------------------------------------------- /gci/namespace-info.vala.in: -------------------------------------------------------------------------------- 1 | /* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */ 2 | /* Attr.vala 3 | * 4 | * Copyright (C) 2019 Daniel Espinosa 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * Authors: 21 | * Daniel Espinosa 22 | */ 23 | [CCode (gir_namespace = "GCi", gir_version = "@API_VERSION@", cheader_filename = "gci/@PROJECT_NAME@.h")] 24 | namespace GCi {} 25 | -------------------------------------------------------------------------------- /gnome-calculator.doap: -------------------------------------------------------------------------------- 1 | 6 | 7 | GNOME Calculator 8 | Desktop calculator 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Vala 21 | Calculator is an application that solves mathematical equations and is suitable as a default application in a Desktop environment 22 | 23 | 24 | Robert Roth 25 | 26 | robertroth 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /help/C/absolute.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Absolute Values 10 | 11 |

12 | Absolute values are calculated using the | symbol or abs function. 13 |

14 | 15 |

16 | |−1| 17 |

18 |

19 | abs (−1) 20 |

21 |
22 |
23 | -------------------------------------------------------------------------------- /help/C/base.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Number Bases 10 | 11 |

12 | To enter numbers in a particular number base use subscript numbers. 13 | The following numbers are equivalent. 14 |

15 | 16 |

17 | 1001011₂ 18 |

19 |

20 | 113₈ 21 |

22 |

23 | 75 24 |

25 |

26 | 4B₁₆ 27 |

28 |
29 |

30 | When in programming mode, use the drop-down menu to change the base of the calculation. 31 |

32 |

33 | Keyboard shortcuts can be used to switch to Binary (CtrlB), Octal (CtrlO), Decimal (CtrlD) and Hexadecimal (CtrlH) modes. 34 |

35 |

36 | To convert numbers to other base on the fly, Number Base conversion can be used. 37 |

38 |
39 | -------------------------------------------------------------------------------- /help/C/boolean.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Boolean Algebra 10 | 11 |

12 | Boolean algebra can be calculated using the following operators and functions. 13 |

14 |

15 | The result of some operations depend on the word size. 16 | To set the word size, press the menu button in the top-right corner of the 17 | window and select Preferences. 18 |

19 |

20 | Buttons for the following symbols and to set the word size are available in programming mode. 21 |

22 | 23 |

24 | Bitwise conjunction can be calculated using the ∧ or AND operators. 25 |

26 | 27 |

28 | 010011₂ ∧ 110101₂ 29 |

30 |

31 | 010011₂ AND 110101₂ 32 |

33 |
34 | 35 |

36 | Bitwise disjunction can be calculated using the ∨ or OR operators. 37 |

38 | 39 |

40 | 010011₂ ∨ 110101₂ 41 |

42 |

43 | 010011₂ OR 110101₂ 44 |

45 |
46 | 47 |

48 | Bitwise exclusive disjunction can be calculated using the ⊻, ⊕ or XOR operators. 49 |

50 | 51 |

52 | 010011₂ ⊻ 110101₂ 53 |

54 |

55 | 010011₂ XOR 110101₂ 56 |

57 |
58 | 59 |

60 | Bitwise complement for the set word size can be calculated using the ¬ or ~ operators or the NOT function. 61 |

62 | 63 |

64 | ¬ 010011₂ 65 |

66 |

67 | NOT 010011₂ 68 |

69 |
70 | 71 |

72 | Bitwise alternative denial for the set word size can be calculated using the ⊼ or NAND operators. 73 |

74 | 75 |

76 | 010011₂ ⊼ 110101₂ 77 |

78 |

79 | 010011₂ NAND 110101₂ 80 |

81 |
82 | 83 |

84 | Bitwise joint denial for the set word size can be calculated using the ⊽ or NOR operators. 85 |

86 | 87 |

88 | 010011₂ ⊽ 110101₂ 89 |

90 |

91 | 010011₂ NOR 110101₂ 92 |

93 |
94 | 95 |

96 | Bitwise biconditional for the set word size can be calculated using the ⊙, XNOR or NXOR operators. 97 |

98 | 99 |

100 | 010011₂ ⊙ 110101₂ 101 |

102 |

103 | 010011₂ XNOR 110101₂ 104 |

105 |
106 |
107 | -------------------------------------------------------------------------------- /help/C/complex.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Complex Numbers 10 | 11 |

12 | Calculator supports complex numbers, as well as the following functions while in Advanced mode. 13 |

14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | 37 | 38 | 39 | 40 | 41 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | 61 |

Re

Returns the real part of a complex number. For example:

20 | 21 |

22 | Re (2-5i) = 2 23 |

24 |
25 |

Im

Returns the imaginary part of a complex number. For example:

31 | 32 |

33 | Im (2-5i) = -5 34 |

35 |
36 |

conj

Returns the conjugate of a complex number. For example:

42 | 43 |

44 | conj (2-5i) = 2+5i 45 |

46 |
47 |

Arg

Returns the argument of a complex number. For example:

53 | 54 |

55 | Arg (2-5i) = -68.1986 56 |

57 |
58 |
62 | 63 | 64 |
65 | -------------------------------------------------------------------------------- /help/C/conv-base.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Number Bases 10 | 11 |

12 | To convert the number to a different base representation use the in operator. 13 |

14 | 15 |

16 | 12 in hex 17 |

18 |

19 | 5 in binary 20 |

21 |

22 | 1A₁₆ in dec 23 |

24 |

25 | 1010₂ in octal 26 |

27 |
28 | 29 |

Number Base conversions must be performed using the keyboard or using 30 | the conversion mode and selecting the 31 | Number Base category.

32 |
33 |
34 | -------------------------------------------------------------------------------- /help/C/conv-character.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Character Codes 10 | 11 |

12 | When in programming mode the á button opens a dialog to convert characters to character codes. 13 |

14 | 15 |

16 | Characters cannot be converted using the keyboard. 17 |

18 |
19 |
20 | -------------------------------------------------------------------------------- /help/C/conv-currency.page: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | Robert Ancell 11 | robert.ancell@gmail.com 12 | 2010 13 | 14 | 15 | Robin Sonefors 16 | ozamosi@flukkost.nu 17 | 2010 18 | 19 | 20 | Ekaterina Gerasimova 21 | kittykat3756@gmail.com 22 | 2014 23 | 24 | 25 | 26 | 27 | Currency 28 | 29 |

To convert currencies, enter the financial 30 | mode, and use the Currency conversion button or enter the 31 | conversion mode and select the 32 | Currency category.

33 | 34 | 35 | 36 |

Enter the amount which you want to convert.

37 |
38 | 39 |

Select the currency that you want to convert from and the currency 40 | that you want to convert to from the drop down below.

41 |
42 |
43 | 44 | 45 |

Currency information is approximate and should not be used for making 46 | financial decisions.

47 |
48 |
49 | -------------------------------------------------------------------------------- /help/C/conv-length.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Length/Area/Volume 10 | 11 |

12 | To convert between length, area and volume units use the in operator. 13 |

14 | 15 |

16 | 6 meters in inches 17 |

18 |

19 | 1 acre in cm² 20 |

21 |

22 | 1 pint in mL 23 |

24 |
25 | 26 |

27 | Length/Area/Volume conversions must be performed using the keyboard or using 28 | the conversion mode and selecting the 29 | length/area/volume category. 30 |

31 |
32 |
33 | -------------------------------------------------------------------------------- /help/C/conv-time.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Time 10 | 11 |

12 | To convert between time use the in operator. 13 |

14 | 15 |

16 | 3 years in hours 17 |

18 |
19 | 20 |

21 | Time conversions must be performed using the keyboard or using 22 | the conversion mode and selecting the 23 | duration category. 24 |

25 |
26 |
27 | -------------------------------------------------------------------------------- /help/C/conv-weight.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Mass 10 | 11 |

12 | To convert between mass use the in operator. 13 |

14 | 15 |

16 | 1kg in pounds 17 |

18 |
19 | 20 |

21 | Mass conversions must be performed using the keyboard or using 22 | the conversion mode and selecting the 23 | mass category. 24 |

25 |
26 |
27 | -------------------------------------------------------------------------------- /help/C/equation.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 0 8 | 9 | 10 | 11 | Basic Equations 12 | 13 |

14 | Equations are entered in standard mathematical form. 15 | For example to add 7 and 2 enter the following: 16 |

17 | 18 |

19 | 7+2 20 |

21 |
22 |

23 | To solve, press the = button with your mouse or the Enter key on your keyboard. 24 |

25 |

26 | Calculations are performed in mathematical order - multiplication and division are performed before addition and subtraction. 27 | The following equation solves to 1 (3×2 = 6, 7−6 = 1). 28 |

29 | 30 |

31 | 7−3×2 32 |

33 |
34 |

35 | To change the order of calculation use parenthesis. 36 | The following equation solves to 8 (7−3 = 4, 4×2 = 8). 37 |

38 | 39 |

40 | (7−3)×2 41 |

42 |
43 |

44 | To clear the display press the C button or Escape. 45 |

46 |
47 | -------------------------------------------------------------------------------- /help/C/factorial.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Factorials 10 | 11 |

12 | Factorials are entered using the ! symbol. 13 | To calculate the factorial of 6 enter the following. 14 |

15 | 16 |

17 | 6! 18 |

19 |
20 |
21 | -------------------------------------------------------------------------------- /help/C/factorize.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Factorization 10 | 11 |

12 | You can factorize the number currently displayed by pressing the fact button. 13 | This button is visible in programming mode. 14 |

15 |
16 | -------------------------------------------------------------------------------- /help/C/figures/org.gnome.Calculator.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /help/C/financial.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Financial Functions 10 |

11 | When in financial mode the following buttons are available. 12 |

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |

Ctrm

Calculate the number of compounding periods necessary to increase an investment of present value to a future value, at a fixed interest rate per compounding period.

Ddb

Calculate the depreciation allowance on an asset for a specified period of time, using the double-declining balance method.

Fv

Calculate the future value of an investment based on a series of equal payments at a periodic interest rate over the number of payment periods in the term.

Gpm

Calculate the resale price of a product, based on the product cost and the wanted gross profit margin.

Pmt

Calculate the amount of the periodic payment of a loan, where payments are made at the end of each payment period.

Pv

Calculate the present value of an investment based on a series of equal payments discounted at a periodic interest rate over the number of payment periods in the term.

Rate

Calculate the periodic interest necessary to increase an investment to a future value, over the number of compounding periods.

Sln

Calculate the straight-line depreciation of an asset for one period. The straight-line method of depreciation divides the depreciable cost evenly over the useful life of an asset. The useful life is the number of periods, typically years, over which an asset is depreciated.

Syd

Calculate the depreciation allowance on an asset for a specified period of time, using the Sum-of-the-Years'-Digits method. This method of depreciation accelerates the rate of depreciation, so that more depreciation expense occurs in earlier periods than in later ones. The useful life is the number of periods, typically years, over which an asset is depreciated.

Term

Calculate the number of payment periods that are necessary during the term of an ordinary annuity, to accumulate a future value, at a periodic interest rate.

55 | 56 |

57 | Financial functions cannot be performed using the keyboard. 58 |

59 |
60 |
61 | -------------------------------------------------------------------------------- /help/C/history.page: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Gopal Krishnan 13 | ingeniumed@outlook.com 14 | 2012, 2013 15 | 16 | 17 | 18 | Sanket Dasgupta 19 | sanketdasgupta@gmail.com 20 | 2016, 2017 21 | 22 | 23 | 24 | Pranali Deshmukh 25 | pranali21293@gmail.com 26 | 2020 27 | 28 | 29 | 30 | Using the History View 31 | 32 |

33 | The History View is located above the entry box and is designed to show 34 | your previous calculations in the form of a scrollable list that can be 35 | clicked and scrolled through using a mouse. 36 |

37 |

38 | Once an entry has been selected, it will immediately show up in the entry box for you to manipulate and use. 39 |

40 |

41 | Finally, there is no upper limit on the number of calculations that can 42 | show up in the list for you to use. 43 |

44 |
45 | -------------------------------------------------------------------------------- /help/C/index.page: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | Calculator Help 8 | Calculator Help 9 | Calculator Help 10 | 11 | Robert Ancell 12 | robert.ancell@gmail.com 13 | 14 | 15 | 16 | 17 | <media type="image" src="figures/org.gnome.Calculator.svg" width="48px" height="48px" its:translate="no" /> Calculator Help 18 | 19 |
20 | User Interface 21 |
22 | 23 |
24 | Equations 25 |
26 | 27 |
28 | Numbers 29 |
30 | 31 |
32 | Conversions 33 |
34 | 35 |
36 | Financial Calculations 37 |
38 |
39 | -------------------------------------------------------------------------------- /help/C/keyboard.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Pranali Deshmukh 10 | pranali21293@gmail.com 11 | 2020 12 | 13 | 14 | 15 | Using the Keyboard 16 | 17 |

18 | All mathematical equations can be entered using the keyboard. 19 |

20 |

21 | The following key combinations can be used to enter keys that may not be available on your keyboard. 22 |

23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |

×

*

÷

/

^

* twice

CtrlR

π

CtrlP

45 |

46 | To enter superscript numbers use Ctrlnumber, for subscript numbers use Altnumber. 47 |

48 |
49 | -------------------------------------------------------------------------------- /help/C/legal.xml: -------------------------------------------------------------------------------- 1 | 3 |

This work is licensed under a 4 | Creative Commons 5 | Attribution-Share Alike 3.0 Unported License.

6 |

As a special exception, the copyright holders give you permission to copy, 7 | modify, and distribute the example code contained in this document under the 8 | terms of your choosing, without restriction.

9 |
10 | -------------------------------------------------------------------------------- /help/C/logarithm.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Logarithms 10 | 11 |

12 | Logarithms can be calculated using the log function. 13 |

14 | 15 |

16 | log 100 17 |

18 |
19 |

20 | To calculate a logarithm in a different base use a subscript number after the function. 21 |

22 | 23 |

24 | log₂ 32 25 |

26 |
27 |

28 | To calculate a natural logarithm use the ln function. 29 |

30 | 31 |

32 | ln 1.32 33 |

34 |
35 |

36 | Euler's number can be entered by using the variable e. 37 |

38 | 39 |

40 | e^1.32 41 |

42 |
43 |
44 | -------------------------------------------------------------------------------- /help/C/mode-programming.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Programming Mode 10 | 11 |

12 | Programming mode provides the tools required for common mathematical operations in software development. For example, programming mode makes math on hexadecimal numbers very easy. It also supports common boolean functions like NOT, AND, OR, etc. A binary view for numbers up to 64 bits long is displayed, where the user can manually toggle each bit using the mouse cursor. 13 |

14 |

15 | Additionally, bit-shifting operations are possible by using the and buttons. Modulo arithmetic can be accomplished using the mod button. 16 |

17 |

18 | The default word size for boolean, one's complement, and two's complement functions can be changed both in the Preferences menu, or by using the word size button in the top right of the keypad while in programming mode. This will affect how results from these functions are shown. For example, here we show the two's complement of the number 6B in 64 bit and 16 bit word sizes: 19 |

20 | 21 |

22 | 64 bit: 23 |

24 |

25 | twos 6B 26 |

27 |

28 | FFFFFFFFFFFFFF95 29 |

30 |

31 | 16 bit: 32 |

33 |

34 | twos 6B 35 |

36 |

37 | FF95 38 |

39 |
40 | 41 |

Attempting to enter a larger number than will fit in the selected word size will result in an Overflow error.

42 |
43 | 44 |
45 | -------------------------------------------------------------------------------- /help/C/modulus.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Modulus Division 10 | 11 |

12 | Modulus division is performed using the mod operator. 13 |

14 | 15 |

16 | 9 mod 5 17 |

18 |
19 |
20 | -------------------------------------------------------------------------------- /help/C/mouse.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Using the Mouse 10 | 11 |

12 | All equations can be entered using the mouse. 13 | To access all buttons there are a number of modes that can be selected from the Mode menu. 14 |

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |

Basic

Provides buttons suitable for basic equations

Advanced

Provides buttons suitable for advanced mathematics such as

Financial

Provides buttons suitable for financial equations

Programming

Provides buttons suitable for computer programmers

33 |
34 | -------------------------------------------------------------------------------- /help/C/number-display.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Result Format 10 | 11 |

12 | To change the format used to display results, press the menu button in the 13 | top-right corner of the window and select the number format to use from the menu. 14 | 15 |

16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |

Automatic

Small results are displayed as Fixed notation while long results are displayed as Scientific notation

Fixed

Results are always displayed as decimal numbers

Scientific

Results are displayed in scientific notation

Engineering

Results are displayed in scientific notation except the exponent is always a multiple of three

34 |

35 | The number of decimal places, if trailing zeroes and if thousands separators are shown can also be configured in Preferences. 36 |

37 |
38 | -------------------------------------------------------------------------------- /help/C/percentage.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Percentages 10 | 11 |

12 | Percentages are calculated using the % symbol. 13 |

14 |

15 | When added or subtracted the percentage symbol resolves to one percent of the value being added or subtracted from. 16 | The following equation calculates the price of a $140 item with 15% tax (140 + (15÷100)×140). 17 |

18 | 19 |

20 | 140+15% 21 |

22 |
23 |

24 | In all other cases the percentage symbol resolves to a fraction out of 100. 25 | The following equation calculates one quarter of 80 apples ((25÷100)×80). 26 |

27 | 28 |

29 | 25%×80 30 |

31 |
32 |
33 | -------------------------------------------------------------------------------- /help/C/power.page: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Ekaterina Gerasimova 12 | kittykat3756@gmail.com 13 | 2015 14 | 15 | 16 | Sebastian Rasmussen 17 | sebras@gmail.com 18 | 2015 19 | 20 | 21 | 22 | Powers and Roots 23 | 24 |

Powers are entered by putting a superscript 25 | number after the value.

26 | 27 | 28 |

29 |
30 | 31 |

The inverse of a number can be entered using the inverse symbol ⁻¹ 32 | (CtrlI).

33 | 34 | 35 |

3⁻¹

36 |
37 | 38 |

Powers can also be calculated using the ^ symbol. This allows the power to 39 | be an equation.

40 | 41 | 42 |

5^(6−2)

43 |
44 | 45 |

If your keyboard does not have a ^ key you can use * 46 | twice.

47 | 48 |

Square roots can be calculated using the √ symbol 49 | (CtrlR).

50 | 51 | 52 |

√2

53 |
54 | 55 |

n-th roots can be calculated by putting a 56 | subscript number before the root sign.

57 | 58 | 59 |

₃√2

60 |
61 | 62 |
63 | -------------------------------------------------------------------------------- /help/C/rounding.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Rounding 10 | 11 |

12 | Nearest integer values tying away from zero are calculated using round function. 13 |

14 | 15 |

16 | round (0.5) 17 |

18 |
19 | 20 |

21 | Nearest interger values toward -∞ also known as floor values are calculated using the ⌊ and ⌋ symbols or floor function. 22 |

23 | 24 |

25 | ⌊0.5⌋ 26 |

27 |

28 | floor (0.5) 29 |

30 |
31 | 32 |

33 | Nearest interger values toward +∞ also known as ceiling values are calculated using the ⌈ and ⌉ symbols or ceil function. 34 |

35 | 36 |

37 | ⌈0.5⌉ 38 |

39 |

40 | ceil (0.5) 41 |

42 |
43 |
44 | -------------------------------------------------------------------------------- /help/C/scientific.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Scientific Notation 10 | 11 |

12 | To enter numbers in scientific format use the ×10y button (CtrlE). 13 | The number mode automatically changes to superscript. 14 | To enter 2×10¹⁰⁰, start by entering the mantissa (2): 15 |

16 | 17 |

18 | 2 19 |

20 |
21 |

22 | Then press the scientific notation button (or press CtrlE): 23 |

24 | 25 |

26 | 2×10 27 |

28 |
29 |

30 | Then enter the exponent (100): 31 |

32 | 33 |

34 | 2×10¹⁰⁰ 35 |

36 |
37 |

38 | To show results in scientific form change the result format. 39 |

40 |
41 | -------------------------------------------------------------------------------- /help/C/superscript.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Pranali Deshmukh 10 | pranali21293@gmail.com 11 | 2020 12 | 13 | 14 | 15 | _ 16 | 17 | 18 | 19 | Superscript and Subscript 20 | 21 |

22 | Some equations may require numbers to be entered in superscript or subscript form, such as: 23 |

24 | 25 |

26 | x³+2x²−5 27 |

28 |
29 |

30 | To enter superscript numbers with the mouse select the number mode using the ↑n and ↓n buttons (available in the Advanced Mode and the Programming Mode). 31 | When one of these modes is active clicking the number buttons will enter numbers in superscript or subscript. 32 | To return to normal number mode click the active number button. 33 |

34 |

35 | To enter superscript numbers use Ctrlnumber, for subscript numbers use Altnumber. 36 |

37 |

38 | The number mode returns to normal when entering the next non-number character, such as "+" or "-". 39 |

40 |
41 | -------------------------------------------------------------------------------- /help/C/trigonometry.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Trigonometry 10 | 11 |

12 | Trigonometry can be performed using the sin, cos, and tan function. 13 |

14 | 15 |

16 | sin 45 17 |

18 |
19 |

20 | To change the angle units used, use one of the following methods: 21 |

22 | 23 |

press the menu button in the top-right 24 | corner of the window and select Preferences

25 |

in advanced mode you can use the Rad/Grad/Deg toggle button 26 | to toggle between units

27 |
28 |

29 | Trigonometry buttons are visible when in Advanced mode. 30 |

31 |

32 | Hyperbolic functions are available by adding "h" to the end of a function. 33 |

34 | 35 |

36 | sinh 0.34 37 |

38 |
39 |

40 | Inverse functions are entered either using the inverse symbol ⁻¹ (CtrlI) or the "a" form of the function. 41 | The following two equations are equivalent. 42 |

43 | 44 |

45 | sin⁻¹ 0.5 46 |

47 |

48 | asin 0.5 49 |

50 |
51 |

52 | To enter π with the keyboard use CtrlP. 53 |

54 |
55 | -------------------------------------------------------------------------------- /help/C/variables.page: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | Variables and Constants 10 | 11 |

12 | To assign a value to a variable use the = symbol or choose the variable to assign to with the x button in advanced mode. 13 | A variable name must only contain upper or lower case characters. 14 |

15 | 16 |

17 | x=5 18 |

19 |

20 | example=82 21 |

22 |
23 |

24 | Variables and constants can be used in any equation and are substituted for their assigned value. 25 | Variables and constants can be inserted using the x button. 26 |

27 | 28 |

29 | 6x+3 30 |

31 |

32 | xy−3x+7y−21 33 |

34 |
35 |

36 | The following variables and constants are always defined. 37 |

38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |

_

Result of previous calculation

rand

Random value in the range [0,1] (changes on each read)

e

Euler's Number

π

Pi

τ

Tau

φ

Golden Ratio

c₀

Light Speed

е

Elementary Charge

Z₀

Impedance of Vacuum

μ₀

Permeability of Vacuum

ε₀

Permittivity of Vacuum

h

Plank‘s Constant

α

Fine-Structure Constant

mₑ

Electron Mass

mₚ

Proton Mass

k

Boltzmann Constant

mᵤ

Atomic Mass Unit

R

Molar Gas Constant

σ

Stefan-Boltzmann Constant

Nᴀ

Avogadro‘s Number

G

Gravitational Constant

g

Earth Acceleration

128 |
129 | -------------------------------------------------------------------------------- /help/LINGUAS: -------------------------------------------------------------------------------- 1 | # please keep this list sorted alphabetically 2 | ca 3 | cs 4 | da 5 | de 6 | el 7 | es 8 | eu 9 | fi 10 | fr 11 | gl 12 | hu 13 | id 14 | it 15 | ja 16 | ko 17 | lv 18 | nl 19 | oc 20 | pl 21 | pt 22 | pt_BR 23 | ro 24 | ru 25 | sl 26 | sv 27 | te 28 | tr 29 | uk 30 | zh_CN 31 | zh_HK 32 | zh_TW 33 | -------------------------------------------------------------------------------- /help/meson.build: -------------------------------------------------------------------------------- 1 | gnome_calculator_help_pages = [ 2 | 'absolute.page', 3 | 'base.page', 4 | 'boolean.page', 5 | 'complex.page', 6 | 'conv-base.page', 7 | 'conv-character.page', 8 | 'conv-currency.page', 9 | 'conv-length.page', 10 | 'conv-time.page', 11 | 'conv-weight.page', 12 | 'equation.page', 13 | 'factorial.page', 14 | 'factorize.page', 15 | 'financial.page', 16 | 'functions.page', 17 | 'history.page', 18 | 'index.page', 19 | 'keyboard.page', 20 | 'legal.xml', 21 | 'logarithm.page', 22 | 'modulus.page', 23 | 'mouse.page', 24 | 'number-display.page', 25 | 'percentage.page', 26 | 'power.page', 27 | 'rounding.page', 28 | 'scientific.page', 29 | 'superscript.page', 30 | 'trigonometry.page', 31 | 'variables.page', 32 | ] 33 | 34 | gnome_calculator_help_media = [ 35 | 'figures/org.gnome.Calculator.svg', 36 | ] 37 | 38 | gnome.yelp(meson.project_name(), 39 | sources: gnome_calculator_help_pages, 40 | media: gnome_calculator_help_media 41 | ) 42 | -------------------------------------------------------------------------------- /lib/meson.build: -------------------------------------------------------------------------------- 1 | libcalculator_sources = [ 2 | 'currency.vala', 3 | 'currency-provider.vala', 4 | 'equation.vala', 5 | 'equation-lexer.vala', 6 | 'equation-parser.vala', 7 | 'financial.vala', 8 | 'function-manager.vala', 9 | 'math-equation.vala', 10 | 'math-function.vala', 11 | 'math-variables.vala', 12 | 'number.vala', 13 | 'serializer.vala', 14 | 'unit.vala', 15 | 'providers/imf-provider.vala', 16 | 'providers/ecb-provider.vala', 17 | 'providers/unt-provider.vala', 18 | 'providers/boc-provider.vala', 19 | ] 20 | 21 | libcalculator_vala_flags = [ 22 | '--target-glib', glib_min_version, 23 | ] 24 | 25 | libcalculator_c_flags = [ 26 | '-include', 'config.h', 27 | ] 28 | 29 | libcalculator_deps = [ 30 | gio, 31 | glib, 32 | gobject, 33 | gtk, 34 | gtksourceview, 35 | libadwaita, 36 | libsoup, 37 | libxml, 38 | mpc, 39 | mpfr, 40 | posix, 41 | libmpfr_inc_libh_dep 42 | ] 43 | 44 | libcalculator = static_library('calculator', libcalculator_sources, 45 | dependencies: libcalculator_deps, 46 | c_args: libcalculator_c_flags, 47 | vala_args: libcalculator_vala_flags, 48 | include_directories: config_h_dir, 49 | link_with: [ lib_mpfrg ], 50 | install: false, 51 | ) 52 | -------------------------------------------------------------------------------- /lib/mpfr-glue.vala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Phillip Wood 3 | * 4 | * GNOME Calculator - mpfr-glue.vala 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | * 19 | * Authors: Phillip Wood 20 | */ 21 | 22 | namespace MPFRG 23 | { 24 | [Compact] 25 | public class RealRef { 26 | public MPFR.Real val; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/providers/boc-provider.vala: -------------------------------------------------------------------------------- 1 | public class BCCurrencyProvider : AbstractCurrencyProvider { 2 | private string currency { get; private set; } 3 | private string currency_filename { get; private set; } 4 | 5 | public override string rate_filepath { owned get { 6 | return Path.build_filename (Environment.get_user_cache_dir (), "gnome-calculator", "%s.xml".printf (currency_filename)); } } 7 | 8 | public override string rate_source_url { owned get { 9 | return "https://exchange-api.gnome.org/boc/%s.xml".printf (currency_filename); } } 10 | 11 | public override string attribution_link { owned get { 12 | return "https://www.bankofcanada.ca/valet/observations/%s/xml?recent=1".printf (currency_filename); } } 13 | 14 | public override string provider_name { get { 15 | return _("Bank of Canada"); } } 16 | 17 | public override string source_name { owned get { return "BC-%s".printf (currency);} } 18 | 19 | protected override bool do_load_rates () 20 | { 21 | var cad_rate = get_base_currency (); // based on CAD 22 | if (cad_rate == null) 23 | return false; 24 | 25 | Xml.Parser.init (); 26 | var document = Xml.Parser.read_file (rate_filepath); 27 | if (document == null) 28 | { 29 | warning ("Couldn't parse rate file %s", rate_filepath); 30 | return false; 31 | } 32 | 33 | var xpath_ctx = new Xml.XPath.Context (document); 34 | if (xpath_ctx == null) 35 | { 36 | warning ("Couldn't create XPath context"); 37 | return false; 38 | } 39 | 40 | var xpath_obj = xpath_ctx.eval_expression ("//observations/o[last()]/v"); 41 | if (xpath_obj == null) 42 | { 43 | warning ("Couldn't create XPath object"); 44 | return false; 45 | } 46 | var xpath_date = xpath_ctx.eval_expression ("//observations/o[last()]/@d"); 47 | var date = xpath_date->nodesetval != null ? xpath_date->nodesetval->item(0)->get_content () : null; 48 | var node = xpath_obj->nodesetval->item (0); 49 | var rate = node->get_content (); 50 | 51 | set_rate (currency, rate, cad_rate.get_value (), date); 52 | 53 | return base.do_load_rates (); 54 | } 55 | 56 | private void set_rate (string name, string value, Number cad_rate, string? date) 57 | { 58 | debug ("Using BC rate of %s for %s", value, name); 59 | var r = mp_set_from_string (value); 60 | var c = register_currency (name, source_name, cad_rate.divide (r), date); 61 | } 62 | 63 | public BCCurrencyProvider (CurrencyManager _currency_manager, string currency, string currency_filename) 64 | { 65 | Object(currency_manager: _currency_manager, base_currency_symbol: "CAD"); 66 | this.currency = currency; 67 | this.currency_filename = currency_filename; 68 | _currency_manager.add_provider (this); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /lib/providers/unt-provider.vala: -------------------------------------------------------------------------------- 1 | public class UnCurrencyProvider : AbstractCurrencyProvider { 2 | public override string rate_filepath { owned get { 3 | return Path.build_filename (Environment.get_user_cache_dir (), "gnome-calculator", "un-daily.xls"); } } 4 | 5 | public override string rate_source_url { owned get { 6 | return "https://exchange-api.gnome.org/unt/un-daily.xls"; } } 7 | 8 | public override string attribution_link { owned get { 9 | return "https://treasury.un.org/operationalrates/OperationalRates.php"; } } 10 | 11 | public override string provider_name { get { 12 | return _("United Nations Treasury"); } } 13 | 14 | public override string source_name { owned get { return "UNT";} } 15 | 16 | private HashTable get_currency_map () { 17 | HashTable name_map = new HashTable (str_hash, str_equal); 18 | name_map.insert ("JMD", "Jamaican Dollar"); 19 | name_map.insert ("ARS", "Argentine Peso"); 20 | name_map.insert ("EGP", "Egyptian Pound"); 21 | name_map.insert ("UAH", "Ukrainian Hryvnia"); 22 | name_map.insert ("NGN", "Nigerian Naira"); 23 | name_map.insert ("VND", "Vietnamese Dong"); 24 | return name_map; 25 | } 26 | 27 | protected override bool do_load_rates () 28 | { 29 | var usd_currency = get_base_currency (); // based on USD 30 | if (usd_currency == null) 31 | return false; 32 | 33 | var currency_map = get_currency_map (); 34 | string data; 35 | try 36 | { 37 | FileUtils.get_contents (rate_filepath, out data); 38 | } 39 | catch (Error e) 40 | { 41 | warning ("Failed to read exchange rates: %s", e.message); 42 | return false; 43 | } 44 | 45 | var lines = data.split ("\r\n", 0); 46 | 47 | var in_data = false; 48 | var usd_rate = usd_currency.get_value (); 49 | 50 | foreach (var line in lines) 51 | { 52 | line = line.chug (); 53 | 54 | /* Start after first blank line, stop on next */ 55 | if (line == "") 56 | { 57 | if (!in_data) 58 | { 59 | in_data = true; 60 | continue; 61 | } 62 | else 63 | break; 64 | } 65 | if (!in_data) 66 | continue; 67 | 68 | var tokens = line.split ("\t", 0); 69 | int value_index = 4; 70 | int date_index = 3; 71 | int symbol_index = 2; 72 | if (value_index <= tokens.length && symbol_index <= tokens.length) 73 | { 74 | var name = tokens [symbol_index]; 75 | var value = tokens [value_index].chug (); 76 | if (name != null && value != null && get_currency (name) == null && currency_map.lookup (name) != null) { 77 | var r = mp_set_from_string (value); 78 | debug ("Registering %s with value '%s'\r\n", name, value); 79 | var v = usd_rate.multiply (r); 80 | var c = register_currency (name, source_name, v, tokens[date_index]); 81 | } 82 | } 83 | } 84 | return base.do_load_rates (); 85 | } 86 | 87 | public UnCurrencyProvider (CurrencyManager _currency_manager) 88 | { 89 | Object(currency_manager: _currency_manager, base_currency_symbol: "USD"); 90 | _currency_manager.add_provider (this); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /libmpfr/meson.build: -------------------------------------------------------------------------------- 1 | 2 | lib_mpfrg_sources = files([ 3 | 'mpfr-glue.vala' 4 | ]) 5 | 6 | libmpfr_inc_libh = include_directories ('.') 7 | libmpfr_inc_libh_dep = declare_dependency (include_directories : libmpfr_inc_libh) 8 | 9 | libmpfr_vapi_dir = meson.current_build_dir() 10 | 11 | lib_mpfrg = static_library ('mpfrg', 12 | lib_mpfrg_sources, 13 | vala_header: 'mpfrg.h', 14 | vala_vapi: 'mpfrg.vapi', 15 | dependencies: [ 16 | gio, 17 | mpc, 18 | mpfr, 19 | ], 20 | install: false, 21 | ) 22 | -------------------------------------------------------------------------------- /libmpfr/mpfr-glue.vala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Phillip Wood 3 | * 4 | * GNOME Calculator - mpfr-glue.vala 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | * 19 | * Authors: Phillip Wood 20 | */ 21 | 22 | namespace MPFRG 23 | { 24 | [Compact] 25 | public class RealRef { 26 | public MPFR.Real val; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('disable-ui', type : 'boolean', value : false, description : 'Disable GTK+ program') 2 | option('vala-version', type: 'string', value : '', description : 'Use another version of Vala (only the latest is officially supported)') 3 | option('disable-introspection', type : 'boolean', value : false, description : 'Disable GObject Introspection Typelib generation') 4 | option('ui-tests', type : 'boolean', value : false, description : 'Execute UI tests: requires X/Wayland/Broadway/Windows server') 5 | option('libpath', type: 'string', value : '', description : 'Used to add search path for libraries like mpc') 6 | option('development', type: 'boolean', value: false, description: 'If this is a development build') 7 | option('gcalc', type: 'boolean', value: true, description: 'Build GCalc library') 8 | option('gci', type: 'boolean', value: true, description: 'Build GCalc UI library') 9 | option('app', type: 'boolean', value: true, description: 'Build GNOME Calculator Application') 10 | option('doc', type: 'boolean', value: true, description: 'Build GCalc and/or GCi documentation') 11 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | ab 2 | af 3 | am 4 | ar 5 | as 6 | ast 7 | az 8 | be@latin 9 | be 10 | bg 11 | bn_IN 12 | bn 13 | bs 14 | ca 15 | ca@valencia 16 | cs 17 | cy 18 | da 19 | de 20 | dz 21 | el 22 | en_CA 23 | en_GB 24 | en@shaw 25 | eo 26 | es 27 | et 28 | eu 29 | fa 30 | fi 31 | fil 32 | fo 33 | fr 34 | fur 35 | ga 36 | gd 37 | gl 38 | gu 39 | he 40 | hi 41 | hr 42 | hu 43 | hy 44 | id 45 | it 46 | ja 47 | ka 48 | kab 49 | kk 50 | km 51 | kn 52 | ko 53 | ku 54 | lt 55 | lv 56 | mai 57 | mg 58 | mjw 59 | mk 60 | ml 61 | mn 62 | mr 63 | ms 64 | my 65 | nb 66 | ne 67 | nl 68 | nn 69 | oc 70 | or 71 | pa 72 | pl 73 | pt_BR 74 | pt 75 | ro 76 | ru 77 | rw 78 | si 79 | sk 80 | sl 81 | sq 82 | sr@latin 83 | sr 84 | sv 85 | ta 86 | te 87 | tg 88 | th 89 | tk 90 | tr 91 | ug 92 | uk 93 | vi 94 | xh 95 | zh_CN 96 | zh_HK 97 | zh_TW 98 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | # List of source files containing translatable strings. 2 | # Please keep this file sorted alphabetically. 3 | data/org.gnome.Calculator.desktop.in 4 | data/org.gnome.Calculator.metainfo.xml.in 5 | data/org.gnome.calculator.gschema.xml 6 | lib/currency-provider.vala 7 | lib/currency.vala 8 | lib/equation-lexer.vala 9 | lib/equation-parser.vala 10 | lib/equation.vala 11 | lib/financial.vala 12 | lib/function-manager.vala 13 | lib/math-equation.vala 14 | lib/math-function.vala 15 | lib/math-variables.vala 16 | lib/number.vala 17 | lib/providers/boc-provider.vala 18 | lib/providers/ecb-provider.vala 19 | lib/providers/imf-provider.vala 20 | lib/providers/unt-provider.vala 21 | lib/serializer.vala 22 | lib/unit.vala 23 | search-provider/search-provider.vala 24 | src/buttons-advanced.vala 25 | src/buttons-programming.vala 26 | src/gcalccmd.vala 27 | src/gnome-calculator.vala 28 | src/math-buttons.vala 29 | src/math-converter.vala 30 | src/math-display.vala 31 | src/math-function-popover.vala 32 | src/math-popover.vala 33 | src/math-preferences.vala 34 | src/math-variable-popover.vala 35 | src/math-window.vala 36 | src/ui/buttons-advanced.ui 37 | src/ui/buttons-basic.ui 38 | src/ui/buttons-conversion.ui 39 | src/ui/buttons-financial.ui 40 | src/ui/buttons-programming.ui 41 | src/ui/math-converter.ui 42 | src/ui/math-display.ui 43 | src/ui/math-function-popover.ui 44 | src/ui/math-preferences.ui 45 | src/ui/math-shortcuts.ui 46 | src/ui/math-variable-popover.ui 47 | src/ui/math-window.ui 48 | -------------------------------------------------------------------------------- /po/POTFILES.skip: -------------------------------------------------------------------------------- 1 | gcalc/ 2 | lib/currency.c 3 | lib/currency-provider.c 4 | lib/equation.c 5 | lib/equation-lexer.c 6 | lib/equation-parser.c 7 | lib/financial.c 8 | lib/function-manager.c 9 | lib/math-equation.c 10 | lib/math-function.c 11 | lib/math-variables.c 12 | lib/number.c 13 | lib/providers/boc-provider.c 14 | lib/providers/ecb-provider.c 15 | lib/providers/imf-provider.c 16 | lib/providers/unt-provider.c 17 | lib/serializer.c 18 | lib/unit.c 19 | search-provider/search-provider.c 20 | src/buttons-advanced.c 21 | src/buttons-programming.c 22 | src/gcalccmd.c 23 | src/gnome-calculator.c 24 | src/math-buttons.c 25 | src/math-converter.c 26 | src/math-display.c 27 | src/math-function-popover.c 28 | src/math-popover.c 29 | src/math-preferences.c 30 | src/math-variable-popover.c 31 | src/math-window.c 32 | tests/ 33 | -------------------------------------------------------------------------------- /po/meson.build: -------------------------------------------------------------------------------- 1 | i18n.gettext(meson.project_name(), 2 | preset: 'glib' 3 | ) 4 | -------------------------------------------------------------------------------- /search-provider/meson.build: -------------------------------------------------------------------------------- 1 | search_provider_sources = [ 2 | 'search-provider.vala', 3 | ] 4 | 5 | search_provider_deps = [ 6 | gio, 7 | glib, 8 | gobject, 9 | gtk, 10 | gtksourceview, 11 | mpc, 12 | mpfr, 13 | posix, 14 | libmpfr_inc_libh_dep 15 | ] 16 | 17 | search_provider_vala_flags = [ 18 | '--vapidir=' + meson.current_source_dir(), 19 | '--pkg', 'config', 20 | ] 21 | 22 | search_provider_c_flags = [ 23 | '-include', 'config.h', 24 | ] 25 | 26 | search_provider_includes = [ 27 | config_h_dir, 28 | include_directories('../lib'), 29 | ] 30 | 31 | # The executable 32 | executable('gnome-calculator-search-provider', search_provider_sources, 33 | dependencies: search_provider_deps, 34 | link_with: [libcalculator, lib_mpfrg], 35 | install_dir: get_option('libexecdir'), 36 | include_directories: search_provider_includes, 37 | vala_args: [ 38 | search_provider_vala_flags, 39 | '--vapidir=' + gcalc_vapi_dir 40 | ], 41 | c_args: search_provider_c_flags, 42 | install: true, 43 | ) 44 | 45 | # The search-provider file for GNOME shell 46 | install_data('org.gnome.Calculator-search-provider.ini', 47 | install_dir: join_paths(get_option('datadir'), 'gnome-shell', 'search-providers'), 48 | ) 49 | 50 | # The DBUS service file 51 | dbusconf = configuration_data() 52 | dbusconf.set('libexecdir', libexec_dir) 53 | 54 | configuration_file = configure_file( 55 | input: 'org.gnome.Calculator.SearchProvider.service.in', 56 | output: 'org.gnome.Calculator.SearchProvider.service', 57 | configuration: dbusconf, 58 | ) 59 | 60 | install_data(configuration_file, 61 | install_dir: join_paths(get_option('datadir'), 'dbus-1', 'services'), 62 | ) 63 | -------------------------------------------------------------------------------- /search-provider/org.gnome.Calculator-search-provider.ini: -------------------------------------------------------------------------------- 1 | [Shell Search Provider] 2 | DesktopId=org.gnome.Calculator.desktop 3 | BusName=org.gnome.Calculator.SearchProvider 4 | ObjectPath=/org/gnome/Calculator/SearchProvider 5 | Version=2 6 | -------------------------------------------------------------------------------- /search-provider/org.gnome.Calculator.SearchProvider.service.in: -------------------------------------------------------------------------------- 1 | [D-BUS Service] 2 | Name=org.gnome.Calculator.SearchProvider 3 | Exec=@libexecdir@/gnome-calculator-search-provider 4 | -------------------------------------------------------------------------------- /src/buttons-advanced.vala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Robert Ancell 3 | * 4 | * This program is free software: you can redistribute it and/or modify it under 5 | * the terms of the GNU General Public License as published by the Free Software 6 | * Foundation, either version 3 of the License, or (at your option) any later 7 | * version. See http://www.gnu.org/copyleft/gpl.html the full text of the 8 | * license. 9 | */ 10 | 11 | [GtkTemplate (ui = "/org/gnome/calculator/buttons-advanced.ui")] 12 | public class AdvancedButtonPanel : Adw.BreakpointBin 13 | { 14 | private MathEquation equation; 15 | 16 | [GtkChild] 17 | private unowned Adw.Carousel carousel; 18 | [GtkChild] 19 | private unowned Gtk.Widget carousel_dots; 20 | [GtkChild] 21 | private unowned Gtk.Widget math_box; 22 | [GtkChild] 23 | private unowned Gtk.Widget basic; 24 | [GtkChild] 25 | private unowned Gtk.Widget advanced; 26 | 27 | [GtkChild] 28 | private unowned Gtk.Button calc_numeric_point_button; 29 | [GtkChild] 30 | private unowned Gtk.MenuButton calc_memory_button; 31 | [GtkChild] 32 | private unowned Gtk.MenuButton calc_function_button; 33 | [GtkChild] 34 | private unowned Gtk.Button calc_inverse_modifier_button; 35 | [GtkChild] 36 | private unowned Gtk.Button calc_angle_units_button; 37 | 38 | private SimpleActionGroup action_group = new SimpleActionGroup (); 39 | private const ActionEntry[] action_entries = { 40 | {"set-angle-units", on_set_angle_units}, 41 | }; 42 | 43 | public AdvancedButtonPanel (MathButtons buttons) 44 | { 45 | equation = buttons.equation; 46 | action_group.add_action_entries (action_entries, this); 47 | insert_action_group ("cal", action_group); 48 | correct_text_direction (); 49 | calc_numeric_point_button.set_label (equation.serializer.get_radix ().to_string ()); 50 | calc_memory_button.popover = new MathVariablePopover (equation); 51 | calc_function_button.popover = new MathFunctionPopover (equation); 52 | 53 | buttons.notify["mode"].connect (() => carousel.scroll_to (carousel.get_nth_page (0), false)); 54 | buttons.bind_property ("inverse", calc_inverse_modifier_button, "active", BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE); 55 | equation.notify["angle-units"].connect (update_angle_units_button); 56 | update_angle_units_button (); 57 | } 58 | 59 | private void correct_text_direction () 60 | { 61 | carousel.set_direction (Gtk.TextDirection.LTR); 62 | carousel_dots.set_direction (Gtk.TextDirection.LTR); 63 | math_box.set_direction (Gtk.TextDirection.LTR); 64 | basic.set_direction (Gtk.TextDirection.LTR); 65 | advanced.set_direction (Gtk.TextDirection.LTR); 66 | } 67 | 68 | private void on_set_angle_units () 69 | { 70 | equation.angle_units = (equation.angle_units + 2) % 3; 71 | } 72 | 73 | private void update_angle_units_button () 74 | { 75 | string[] unit_symbols = {"Rad", "Deg", "Grad"}; 76 | string[] unit_names = {_("Radians"), _("Degrees"), _("Gradians")}; 77 | calc_angle_units_button.label = unit_symbols[equation.angle_units]; 78 | calc_angle_units_button.tooltip_text = _("Angle Unit: %s").printf (unit_names[equation.angle_units]); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/buttons-basic.vala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008-2012 Robert Ancell 3 | * 4 | * This program is free software: you can redistribute it and/or modify it under 5 | * the terms of the GNU General Public License as published by the Free Software 6 | * Foundation, either version 3 of the License, or (at your option) any later 7 | * version. See http://www.gnu.org/copyleft/gpl.html the full text of the 8 | * license. 9 | */ 10 | 11 | [GtkTemplate (ui = "/org/gnome/calculator/buttons-basic.ui")] 12 | public class BasicButtonPanel : Adw.Bin 13 | { 14 | [GtkChild] 15 | private unowned Gtk.Widget basic; 16 | [GtkChild] 17 | private unowned Gtk.Button calc_numeric_point_button; 18 | [GtkChild] 19 | private unowned Gtk.MenuButton calc_memory_button; 20 | [GtkChild] 21 | private unowned Gtk.MenuButton calc_function_button; 22 | 23 | public BasicButtonPanel (MathButtons buttons) 24 | { 25 | basic.set_direction (Gtk.TextDirection.LTR); 26 | calc_numeric_point_button.set_label (buttons.equation.serializer.get_radix ().to_string ()); 27 | calc_memory_button.popover = new MathVariablePopover (buttons.equation); 28 | calc_function_button.popover = new MathFunctionPopover (buttons.equation); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/gcalccmd.vala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 Rich Burridge 3 | * Copyright (C) 2012 Robert Ancell 4 | * 5 | * This program is free software: you can redistribute it and/or modify it under 6 | * the terms of the GNU General Public License as published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) any later 8 | * version. See http://www.gnu.org/copyleft/gpl.html the full text of the 9 | * license. 10 | */ 11 | 12 | private const int MAXLINE = 1024; 13 | 14 | private static Serializer result_serializer; 15 | 16 | static void solve (string equation) 17 | { 18 | var tsep_string = Posix.nl_langinfo (Posix.NLItem.THOUSEP); 19 | if (tsep_string == null || tsep_string == "") 20 | tsep_string = " "; 21 | 22 | var decimal = Posix.nl_langinfo (Posix.NLItem.RADIXCHAR); 23 | if (decimal == null) 24 | decimal = ""; 25 | 26 | string? error_token = null; 27 | var e = new Equation (equation.replace (tsep_string, "").replace (decimal, ".")); 28 | e.base = 10; 29 | e.wordlen = 32; 30 | e.angle_units = AngleUnit.DEGREES; 31 | 32 | ErrorCode ret; 33 | uint representation_base; 34 | var z = e.parse (out representation_base, out ret, out error_token); 35 | 36 | result_serializer.set_representation_base (representation_base); 37 | if (z != null) 38 | { 39 | var str = result_serializer.to_string (z); 40 | if (result_serializer.error != null) 41 | { 42 | stderr.printf ("%s\n", result_serializer.error); 43 | result_serializer.error = null; 44 | } 45 | else 46 | stdout.printf ("%s\n", str); 47 | } 48 | else if (ret == ErrorCode.MP) 49 | stderr.printf ("Error %s\n", (Number.error != null) ? Number.error : error_token); 50 | else 51 | stderr.printf ("Error %d\n", ret); 52 | } 53 | 54 | public static int main (string[] args) 55 | { 56 | /* Seed random number generator. */ 57 | var now = new DateTime.now_utc (); 58 | bool requires_new_line = false; 59 | 60 | Random.set_seed (now.get_microsecond ()); 61 | 62 | Intl.setlocale (LocaleCategory.ALL, ""); 63 | 64 | result_serializer = new Serializer (DisplayFormat.AUTOMATIC, 10, 9); 65 | 66 | var settings = new Settings ("org.gnome.calculator"); 67 | CurrencyManager.get_default (false).refresh_interval = settings.get_int ("refresh-interval"); 68 | CurrencyManager.get_default (false).refresh_sync (); 69 | 70 | if (args.length == 2) { 71 | solve (args[1]); 72 | return Posix.EXIT_SUCCESS; 73 | } 74 | 75 | var buffer = new char[1024]; 76 | while (true) 77 | { 78 | stdout.printf ("> "); 79 | var line = stdin.gets (buffer); 80 | 81 | if (line != null) 82 | line = line.strip (); 83 | else 84 | requires_new_line = true; 85 | 86 | if (line == null || line == "exit" || line == "quit" || line == "") 87 | break; 88 | 89 | solve (line); 90 | } 91 | 92 | if (requires_new_line) 93 | stdout.printf ("\n"); 94 | 95 | return Posix.EXIT_SUCCESS; 96 | } 97 | -------------------------------------------------------------------------------- /src/meson.build: -------------------------------------------------------------------------------- 1 | # gnome-calculator executable 2 | gnome_calculator_vala_sources = [ 3 | 'buttons-advanced.vala', 4 | 'buttons-basic.vala', 5 | 'buttons-conversion.vala', 6 | 'buttons-financial.vala', 7 | 'buttons-programming.vala', 8 | 'gnome-calculator.vala', 9 | 'math-buttons.vala', 10 | 'math-converter.vala', 11 | 'math-display.vala', 12 | 'math-preferences.vala', 13 | 'math-popover.vala', 14 | 'math-function-popover.vala', 15 | 'math-variable-popover.vala', 16 | 'math-window.vala', 17 | 'math-history.vala', 18 | ] 19 | 20 | gnome_calculator_resource_files = files('ui/gnome-calculator.gresource.xml') 21 | gnome_calculator_resources = gnome.compile_resources('org.gnome.Calculator', gnome_calculator_resource_files, source_dir : ['ui']) 22 | 23 | gnome_calculator_sources = [ 24 | gnome_calculator_vala_sources, 25 | gnome_calculator_resources, 26 | ] 27 | 28 | gnome_calculator_deps = [ 29 | glib, 30 | gobject, 31 | gtk, 32 | gtksourceview, 33 | libadwaita, 34 | mpc, 35 | mpfr, 36 | posix 37 | ] 38 | 39 | gnome_calculator_vala_flags = [ 40 | '--target-glib', glib_min_version, 41 | '--vapidir=' + meson.current_source_dir(), 42 | '--pkg', 'config', 43 | '--gresources', gnome_calculator_resource_files, 44 | '--vapidir=' + gcalc_vapi_dir 45 | ] 46 | 47 | gnome_calculator_c_flags = [ 48 | '-include', 'config.h', 49 | ] 50 | 51 | gnome_calculator_includes = [ 52 | config_h_dir, 53 | include_directories('../lib'), 54 | ] 55 | 56 | executable('gnome-calculator', gnome_calculator_sources, 57 | dependencies: gnome_calculator_deps, 58 | include_directories: gnome_calculator_includes, 59 | vala_args: gnome_calculator_vala_flags, 60 | c_args: gnome_calculator_c_flags, 61 | link_with: [libcalculator, lib_mpfrg], 62 | install: true, 63 | ) 64 | 65 | 66 | # gcalccmd executable 67 | gcalccmd_sources = [ 68 | 'gcalccmd.vala', 69 | ] 70 | 71 | gcalccmd_deps = [ 72 | gio, 73 | glib, 74 | gobject, 75 | gtk, 76 | gtksourceview, 77 | mpc, 78 | mpfr, 79 | posix, 80 | libmpfr_inc_libh_dep 81 | ] 82 | 83 | gcalccmd_vala_flags = [ 84 | '--vapidir=' + meson.current_source_dir(), 85 | '--pkg', 'config', 86 | '--vapidir=' + gcalc_vapi_dir 87 | ] 88 | 89 | gcalccmd_includes = [ 90 | config_h_dir, 91 | include_directories('../lib'), 92 | ] 93 | 94 | executable('gcalccmd', gcalccmd_sources, 95 | dependencies: gcalccmd_deps, 96 | link_with: [libcalculator, lib_mpfrg], 97 | include_directories: gcalccmd_includes, 98 | vala_args: gcalccmd_vala_flags, 99 | install: true, 100 | ) 101 | -------------------------------------------------------------------------------- /src/ui/gnome-calculator.gresource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | buttons-advanced.ui 5 | buttons-basic.ui 6 | buttons-conversion.ui 7 | buttons-financial.ui 8 | buttons-programming.ui 9 | history-view.ui 10 | history-entry.ui 11 | math-converter.ui 12 | math-display.ui 13 | math-function-popover.ui 14 | math-variable-popover.ui 15 | math-window.ui 16 | math-shortcuts.ui 17 | math-preferences.ui 18 | style.css 19 | style-dark.css 20 | style-hc.css 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/ui/history-entry.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 73 | 74 | -------------------------------------------------------------------------------- /src/ui/history-view.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 30 | 31 | -------------------------------------------------------------------------------- /src/ui/math-function-popover.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 70 | 71 | -------------------------------------------------------------------------------- /src/ui/style-dark.css: -------------------------------------------------------------------------------- 1 | .history-view { 2 | background-color: alpha(white, .05); 3 | } 4 | -------------------------------------------------------------------------------- /src/ui/style-hc.css: -------------------------------------------------------------------------------- 1 | .sourceview, 2 | .history-entry { 3 | border-top-color: @borders; 4 | } 5 | 6 | .math-popover list > row:hover, 7 | .math-popover list > row:active { 8 | box-shadow: inset 0 0 0 1px @borders; 9 | } 10 | 11 | .math-popover .constant-list image { 12 | opacity: 80%; 13 | } 14 | -------------------------------------------------------------------------------- /tests/advanced_mode.feature: -------------------------------------------------------------------------------- 1 | @advanced_mode 2 | Feature: Advanced mode 3 | 4 | Background: 5 | * Make sure that Calculator is running 6 | * Switch to Advanced mode 7 | 8 | Scenario Outline: Simple calculations in advanced mode 9 | * Calculate "" 10 | Then result is "" 11 | 12 | Examples: 13 | | expression | result | 14 | | 123456789 + 987654321 | 1111111110 | 15 | | 987654321 + 0 | 987654321 | 16 | | 987654321 - 987654322 | -1 | 17 | | -98765-0 | -98765 | 18 | | 3/6 | 0.5 | 19 | | -8/2 | -4 | 20 | | 10 / 3 * 3 | 10 | 21 | | 6 / (3 * 2) | 1 | 22 | -------------------------------------------------------------------------------- /tests/basic_mode.feature: -------------------------------------------------------------------------------- 1 | @basic_mode 2 | Feature: Basic mode 3 | 4 | Background: 5 | * Make sure that Calculator is running 6 | * Switch to Basic mode 7 | 8 | @basic_add 9 | Scenario Outline: Add 10 | * Calculate "" 11 | Then result is "" 12 | 13 | Examples: 14 | | expression | result | 15 | | 123456789 + 987654321 | 1111111110 | 16 | | 987654321 + 0 | 987654321 | 17 | | -987 + (-14) | -1001 | 18 | | -0 + 0 | 0 | 19 | 20 | @basic_add @basic_add_overflow 21 | Scenario: Add - overflow 22 | * Calculate "987654321^789456 +123456789" 23 | Then "Precision error" error is displayed 24 | 25 | @basic_subtract 26 | Scenario Outline: Subtract 27 | * Calculate "" 28 | Then result is "" 29 | 30 | Examples: 31 | | expression | result | 32 | | 987654321 - 987654322 | -1 | 33 | | -98765-0 | -98765 | 34 | | 0-0 | 0 | 35 | | -6-(-5) | -1 | 36 | 37 | @basic_subtract @basic_subtract_overflow 38 | Scenario: Subtract overflow 39 | * Calculate "-987654321^98-987654321" 40 | Then "Overflow: the result couldn't be calculated" error is displayed 41 | 42 | @basic_multiply 43 | Scenario: Multiply 44 | * Calculate "10 / 3 * 3" 45 | Then result is "10" 46 | 47 | @basic_divide 48 | Scenario Outline: Divide 49 | * Calculate "" 50 | Then result is "" 51 | 52 | Examples: 53 | | expression | result | 54 | | 3/6 | 0.5 | 55 | | 20/8 | 2.5 | 56 | | 1000000/100000 | 10 | 57 | | -8/2 | -4 | 58 | | -9/-7 | 1.285714286 | 59 | | 3.256/0.36 | 9.044444444 | 60 | | -1/1 | -1 | 61 | | 0/987 | 0 | 62 | | 10/3*3 | 10 | 63 | | 15/99 | 0.151515152 | 64 | 65 | @basic_divide @basic_divide_by_zero 66 | Scenario: Division by zero 67 | * Calculate "5/0" 68 | Then "Division by zero is undefined" error is displayed 69 | 70 | @basic_divide @basic_divide_by_zero_with_decimal_point 71 | Scenario: Division by zero with decimal point 72 | * Calculate "0.0/0.0" 73 | Then "Division by zero is undefined" error is displayed 74 | 75 | @basic_brackets 76 | Scenario Outline: Brackets 77 | * Calculate "" 78 | Then result is "" 79 | 80 | Examples: 81 | | expression | result | 82 | | 6 / (3 * 2) | 1 | 83 | | 0 * ( 1 + 2 + 3 + 4) | 0 | 84 | | (((2 + 8) * (5 / 2)) - 3) | 22 | 85 | -------------------------------------------------------------------------------- /tests/environment.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | from time import sleep 4 | from dogtail.utils import isA11yEnabled, enableA11y 5 | if not isA11yEnabled(): 6 | enableA11y(True) 7 | 8 | from common_steps import App 9 | from dogtail.config import config 10 | import os 11 | 12 | 13 | def before_all(context): 14 | """Setup gnome-calculator stuff 15 | Being executed before all features 16 | """ 17 | 18 | try: 19 | # Skip dogtail actions to print to stdout 20 | config.logDebugToStdOut = False 21 | config.typingDelay = 0.2 22 | 23 | context.app_class = App('gnome-calculator') 24 | 25 | except Exception as e: 26 | print("Error in before_all: %s" % e.message) 27 | 28 | 29 | def after_step(context, step): 30 | try: 31 | if step.status == 'failed' and hasattr(context, "embed"): 32 | # Embed screenshot if HTML report is used 33 | os.system("dbus-send --print-reply --session --type=method_call " + 34 | "--dest='org.gnome.Shell.Screenshot' " + 35 | "'/org/gnome/Shell/Screenshot' " + 36 | "org.gnome.Shell.Screenshot.Screenshot " + 37 | "boolean:true boolean:false string:/tmp/screenshot.png") 38 | context.embed('image/png', open("/tmp/screenshot.png", 'r').read()) 39 | except Exception as e: 40 | print("Error in after_step: %s" % str(e)) 41 | 42 | 43 | def after_scenario(context, scenario): 44 | """Teardown for each scenario 45 | Kill gnome-calculator (in order to make this reliable we send sigkill) 46 | """ 47 | try: 48 | # Stop gnome-calculator 49 | context.app_class.kill() 50 | 51 | # Make some pause after scenario 52 | sleep(1) 53 | except Exception as e: 54 | # Stupid behave simply crashes in case exception has occurred 55 | print("Error in after_scenario: %s" % e.message) 56 | -------------------------------------------------------------------------------- /tests/financial_mode.feature: -------------------------------------------------------------------------------- 1 | @financial_mode 2 | Feature: Financial mode 3 | 4 | Background: 5 | * Make sure that Calculator is running 6 | * Switch to Financial mode 7 | 8 | Scenario Outline: Simple calculations in financial mode 9 | * Calculate "" 10 | Then result is "" 11 | 12 | Examples: 13 | | expression | result | 14 | | 123456789 + 987654321 | 1111111110 | 15 | | 987654321 + 0 | 987654321 | 16 | | 987654321 - 987654322 | -1 | 17 | | -98765-0 | -98765 | 18 | | 3/6 | 0.5 | 19 | | -8/2 | -4 | 20 | | 10 / 3 * 3 | 10 | 21 | | 6 / (3 * 2) | 1 | 22 | -------------------------------------------------------------------------------- /tests/gci-test-entry-controller.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 43 | 44 | -------------------------------------------------------------------------------- /tests/meson.build: -------------------------------------------------------------------------------- 1 | if not get_option ('disable-ui') 2 | 3 | if get_option('app') 4 | 5 | # Common 6 | gnome_calculator_tests_deps = [ 7 | gtk, 8 | gtksourceview, 9 | gio, 10 | glib, 11 | gobject, 12 | libmath, 13 | mpc, 14 | mpfr, 15 | posix, 16 | inc_rooth_dep 17 | ] 18 | 19 | gnome_calculator_tests_includes = [ 20 | include_directories('../lib'), 21 | ] 22 | 23 | # Tests 24 | 25 | test_equation_sources = [ 26 | 'test-equation.vala', 27 | ] 28 | test_equation = executable('test-equation', test_equation_sources, 29 | dependencies: gnome_calculator_tests_deps, 30 | link_with: [libcalculator, lib_mpfrg], 31 | include_directories: gnome_calculator_tests_includes, 32 | ) 33 | test('Equation test', test_equation) 34 | 35 | test_currency_sources = [ 36 | 'test-currency-providers.vala', 37 | ] 38 | 39 | test_currency = executable('test-currency-providers', test_currency_sources, 40 | dependencies: gnome_calculator_tests_deps, 41 | link_with: [libcalculator, lib_mpfrg], 42 | include_directories: gnome_calculator_tests_includes, 43 | ) 44 | tests_root_env = environment({'TESTS_ROOT': meson.current_source_dir()}) 45 | test('Currency test', test_currency, env: tests_root_env) 46 | 47 | 48 | test_number_sources = [ 49 | 'test-number.vala', 50 | ] 51 | test_number = executable('test-number', test_number_sources, 52 | dependencies: gnome_calculator_tests_deps, 53 | link_with: [libcalculator, lib_mpfrg], 54 | include_directories: gnome_calculator_tests_includes, 55 | ) 56 | test('Number test', test_number) 57 | 58 | test_serializer_sources = [ 59 | 'test-serializer.vala', 60 | ] 61 | test_serializer = executable('test-serializer', test_serializer_sources, 62 | dependencies: gnome_calculator_tests_deps, 63 | link_with: [libcalculator, lib_mpfrg], 64 | include_directories: gnome_calculator_tests_includes, 65 | ) 66 | test('Serializer test', test_serializer) 67 | 68 | endif 69 | 70 | if get_option('ui-tests') and get_option('gci') and get_option('gcalc') 71 | gci_test_deps = [ 72 | gee, 73 | gtk, 74 | inc_rooth_dep, 75 | gcalc_inc_libh_dep, 76 | gci_inc_libh_dep 77 | ] 78 | 79 | test_entry_controler_resource_files = files('test-entry-controller.gresource.xml') 80 | test_entry_controler_resources = gnome.compile_resources('test-entry-controller-resources', test_entry_controler_resource_files) 81 | 82 | test_entry_controler_sources = [ 83 | 'test-gci-entry-controller.vala', 84 | ] 85 | test_entry_controler_sources += test_entry_controler_resources 86 | 87 | test_entry_controler = executable('test-entry-controller', test_entry_controler_sources, 88 | dependencies: gci_test_deps, 89 | link_with: [libgci, libgcalc], 90 | ) 91 | test('gci-entry-controller', test_entry_controler) 92 | endif 93 | 94 | endif 95 | 96 | if get_option('gcalc') 97 | tests_deps = [ 98 | gio, 99 | glib, 100 | gobject, 101 | libmath, 102 | mpc, 103 | mpfr, 104 | posix, 105 | gee, 106 | inc_rooth_dep 107 | ] 108 | 109 | test_parsing_sources = [ 110 | 'gcalc-parsing.vala', 111 | ] 112 | 113 | test_parsing = executable('gcalc-parsing', test_parsing_sources, 114 | dependencies:tests_deps, 115 | link_with: [libgcalc, lib_mpfrg], 116 | ) 117 | test('gcalc-parsing', test_parsing) 118 | 119 | 120 | test_solve_basic_sources = [ 121 | 'gcalc-solving-basic.vala', 122 | ] 123 | 124 | test_solve_basic = executable('gcalc-solve-basic', test_solve_basic_sources, 125 | dependencies:tests_deps, 126 | link_with: [libgcalc, lib_mpfrg], 127 | ) 128 | test('gcalc-solve-basic', test_solve_basic) 129 | 130 | endif 131 | -------------------------------------------------------------------------------- /tests/programming_mode.feature: -------------------------------------------------------------------------------- 1 | @programming_mode 2 | Feature: Programming mode 3 | 4 | Background: 5 | * Make sure that Calculator is running 6 | * Switch to Programming mode 7 | 8 | Scenario Outline: Simple calculations in programming mode 9 | * Calculate "" 10 | Then result is "" 11 | 12 | Examples: 13 | | expression | result | 14 | | 123456789 + 987654321 | 1111111110 | 15 | | 987654321 + 0 | 987654321 | 16 | | 987654321 - 987654322 | -1 | 17 | | -98765-0 | -98765 | 18 | | 3/6 | 0.5 | 19 | | -8/2 | -4 | 20 | | 10 / 3 * 3 | 10 | 21 | | 6 / (3 * 2) | 1 | 22 | -------------------------------------------------------------------------------- /tests/steps/steps.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | from behave import step, then 3 | 4 | from dogtail.tree import root 5 | from dogtail.rawinput import typeText 6 | from common_steps import limit_execution_time_to, wait_until 7 | from time import sleep 8 | 9 | 10 | @step(u'Help section "{name}" is displayed') 11 | def help_is_displayed(context, name): 12 | context.yelp = root.application('yelp') 13 | frame = context.yelp.child(roleName='frame') 14 | wait_until(lambda x: x.showing, frame) 15 | sleep(1) 16 | context.assertion.assertEquals(name, frame.name) 17 | 18 | 19 | @step(u'Switch to {mode:w} mode') 20 | def switch_to_basic_mode(context, mode): 21 | context.app.child(roleName='toggle button', name='Menu').click() 22 | context.app.child(roleName='radio button', name='%s Mode' % mode).click() 23 | 24 | 25 | @limit_execution_time_to(seconds=30) 26 | def wait_until_spinner_showing(context): 27 | # Wait until spinner disappears 28 | sleep(0.1) 29 | spinner = context.app.child('Spinner') 30 | while spinner.showing: 31 | sleep(0.1) 32 | 33 | 34 | @step(u'Calculate "{expression}"') 35 | def calculate(context, expression): 36 | typeText(expression) 37 | context.app.child('result').click() 38 | wait_until_spinner_showing(context) 39 | 40 | 41 | @step(u'result is "{result}"') 42 | def verify_result(context, result): 43 | # Replace unicode negative sign to simple '-' 44 | actual = context.app.child(roleName='editbar').text.replace('\xe2\x88\x92', '-') 45 | assert result == actual, "Incorrect result, expected '%s' but was '%s'" % (result, actual) 46 | 47 | 48 | @then(u'"{message}" error is displayed') 49 | def error_message_displayed(context, message): 50 | actual = context.app.child(roleName='editbar').parent.textentry('').text 51 | assert message == actual, "Incorrect error, expected '%s' but was '%s'" % (message, actual) 52 | -------------------------------------------------------------------------------- /tests/test-entry-controller.gresource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | gci-test-entry-controller.ui 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/test-gci-entry-controller.vala: -------------------------------------------------------------------------------- 1 | /* -*- Mode: Vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */ 2 | /* 3 | * GCalc Unit Tests 4 | * Copyright (C) Daniel Espinosa Ortiz 2019 5 | * 6 | * libgda is free software: you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as published 8 | * by the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * libgda is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | * See the GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | */ 19 | using GCalc; 20 | using GCi; 21 | 22 | class Tests { 23 | [GtkTemplate (ui = "/org/gnome/Calculator/gci-test-entry-controller.ui")] 24 | class Window : Gtk.ApplicationWindow { 25 | [GtkChild] 26 | unowned Gtk.Entry entry; 27 | [GtkChild] 28 | unowned Gtk.Button button; 29 | 30 | GCi.EntryController controller; 31 | 32 | construct { 33 | controller = new GCi.EntryController (); 34 | controller.entry = entry; 35 | GLib.Timeout.add (10000, ()=>{ 36 | application.quit (); 37 | }); 38 | button.clicked.connect (()=>{ 39 | message ("Closing..."); 40 | application.quit (); 41 | }); 42 | } 43 | 44 | public Window (Gtk.Application app) { 45 | Object(application: app); 46 | } 47 | } 48 | class Application : Gtk.Application { 49 | public Application () { 50 | Object(application_id: "test.gci.entry.controler", 51 | flags: ApplicationFlags.FLAGS_NONE); 52 | } 53 | 54 | protected override void activate () { 55 | // Create the window of this application and show it 56 | Gtk.ApplicationWindow w = new Window (this); 57 | w.present (); 58 | } 59 | } 60 | static int main (string[] args) 61 | { 62 | GLib.Intl.setlocale (GLib.LocaleCategory.ALL, ""); 63 | Test.init (ref args); 64 | Test.add_func ("/gci/entry/controler", 65 | ()=>{ 66 | var app = new Application (); 67 | app.run (); 68 | }); 69 | return Test.run (); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vapi/config.vapi: -------------------------------------------------------------------------------- 1 | public const string APP_ID; 2 | public const string NAME_PREFIX; 3 | public const string VERSION; 4 | public const string GETTEXT_PACKAGE; 5 | public const string LOCALE_DIR; 6 | public const bool DEVELOPMENT_BUILD; 7 | -------------------------------------------------------------------------------- /vapi/meson.build: -------------------------------------------------------------------------------- 1 | vapis_dir = meson.current_source_dir () 2 | --------------------------------------------------------------------------------