Commit Graph

117 Commits

Author SHA1 Message Date
Michał Janiszewski
841906a4ed Update comment in scicomm.cpp (#549)
While reading this part of code I had hard time understanding the
comment, especially the misused `serious`. I tried rewording it
slightly.
2019-06-17 17:15:35 -07:00
Michał Janiszewski
da9f4ea856 Fix type of m_openParenCount (#550)
m_openParenCount is always used as unsigned and compared against unsigneds
2019-06-17 17:10:15 -07:00
Michał Janiszewski
81aec1ebe8 Drop __inline from conflicting declarations (#545)
`mulnum` et al. are declared `extern` in `ratpak.h`, which conflicts
with the `__inline` used with them. Additionally, most similar functions
don't have such keyword applied to them.
2019-06-10 14:36:05 -07:00
Michał Janiszewski
fe30c7cabc Add CMake project, GCC support (#540)
This is extract from #211 that enables compilation with GCC. With #211
now in the state of bitrot, I would rather try approaching it in smaller
steps that can be hopefully merged quicker, even if it does not provide
full support for all the features #211 provided.

This will _compile_ correctly with my (@janisozaur) GCC, but clang is
more picky about flexible array members and refuses to compile it yet.
I will extract remaining parts of #211 in future PRs.

I marked @fwcd as author, as he did most of the work in #211.
2019-06-06 14:08:31 -07:00
Northurland
d4028cda95 Force compiler to use utf-8 so the project compiles on systems in Chinese (#516) 2019-05-22 10:16:17 -07:00
Rudy Huyn
28888d8df1 Remove Serialize/Deserialize functions never used in StandardCalculatorViewModel, UnitConverter, UnitConverterViewModel and CalculatorManager (#392)
* remove unused serializer

* remove all unused serialization/deserialization from StandardCalculatorViewModel and UnitConverterViewModel

* formatting
2019-05-09 11:01:43 -07:00
Daniel Belcher
9f01c8168b
Secondary formatting changes (#489)
Description of the changes:
Adjusted some of the values in .clang-format
Add clang-format-all.ps1
Fix path to .clang-format in Calculator.sln

How changes were validated:
Manual.
2019-05-02 16:48:33 -07:00
Oleg Abrazhaev
2826d37056 Fix the project code style, as it is not consistent. (#236)
Fixes #202
This PR fixes code style for the project files.

The Problem
Different files in the project use different code style. That is not consistent and leads to harder maintenance of the project.

Description of the changes:
Have investigated and determined the most used code style across the given codebase
Have configured IDE and applied code style to all project files.
Have crafted clang-formatter config.
see https://clang.llvm.org/docs/ClangFormat.html
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
Some cases were fixed manually
How changes were validated:
manual/ad-hoc testing, automated testing

All tests pass as before because these are only code style changes.
Additional
Please review, and let me know if I have any mistake in the code style. In case of any mistake, I will change the configuration and re-apply it to the project.
2019-05-02 11:59:19 -07:00
Daniel Belcher
d21a47d5a1
Compile CalcManager project with or without precompiled headers (#436)
Fixes #324 .

Description of the changes:
In an effort to support other compilers (#109), this change reworks how precompiled headers are handled. For toolchains where precompiled headers are not used, there is unnecessary compilation cost because each source file explicity includes the pch, meaning all system headers in the pch were recompiled for each translation unit. This change modifies the project's files so that each translation unit includes a minimal set of dependent headers. For MSVC users, the precompiled headers option is still enabled and the precompiled header is added to each translation unit using the compiler's Forced Includes option. The end result is that MSVC users still see the same build times, but other toolchains are free to use or not use precompiled headers.

Risks introduced
Given that our CI build uses MSVC, this change introduces the risk that a system header is added to the pch and the CalcManager project builds correctly, but builds could be broken for other toolsets that don't use pch. We know we want to add support for Clang in our CI build (#211). It seems reasonable to also compile without precompiled headers there so that we can regression test this setup.

How changes were validated:
Rebuild CalcManager project. Compile time: ~4.5s.
Disable precompiled headers, keeping explicit include for pch in each source file. Compile time: ~13s.
Remove explicit pch inclusion and add the appropriate headers to each translation unit to allow the project to compile. Compile time: ~8s.
Re-enable pch and include it using the Forced Includes compiler option. MSVC compile time: ~4.5s.
Minor changes
Delete 'targetver.h'. I found this while looking around for system headers in the project. It's unused and unreferenced so let's remove it.
2019-04-17 17:28:45 -07:00
Seulgi Kim
853704c1c2 Add support for Pyeong, a Korean floorspace unit. (#444)
Fixes #382
Description of the changes:
Add Pyeong as an Area conversion unit.
Pyeong shows up only if the user's current region is Korea ( i.e. region is either KP or KR ).
Added Korean translation for Pyeong (평). For other locales, we default to English ( Pyeong ).
How changes were validated:
Manually tested the below

For non-Korean regions, Pyeong does not show up.

Korean region with Korean locale => Pyeong shows up and Pyeong is correctly translated.
pyeong_Korean

Korean region with English locale => Pyeong shows up and Pyeong is in English.
pyeong_English

Korean region with simplified Chinese locale => Pyeong shows up and Pyeong is in English.
pyeong_Chinese
2019-04-16 17:53:08 -07:00
Rudy Huyn
7a7ceb5888 Modify how modulo is calculated in Normal and Scientific mode. (#412)
## Fixes #111

> The modulo operator on this calculator gives the result that is different to the most used calculators.

The current `modrate` function is the equivalent of rem(...)/remainder(...), not mod(...)/modulo(...) available in some popular Math apps. 

### Description of the changes:
- rename `modrate` in `remrate` to be more accurate.
- add `modrate`, calculating modulo similarly to Matlab, Bing, Google calculator, Maxima, Wolfram Alpha and Microsoft Excel 
- Add `RationalMath::Mod` using `modrate` as an alternative to `Rational::operator%` using `remrate`
- Add a helper `SIGN` to retrieve the sign of a `Rational`.
- modify `CalcEngine` to use `modrate` in Normal and Scientific mode and `remrate` in Programmer mode.

### How changes were validated:
- manually and unit tests added
2019-04-16 17:17:24 -07:00
Rudy Huyn
ad25feda6b Keep input when users refresh currency rates (#369)
Fixes #260

Description of the changes:
prevent UnitConverterViewModel to reset values when users click on update rates.
recompute UnitConverter's caches (m_ratioMap and m_categoryToUnits) once rates are updated (but check first if the user did/didn't change the category)

How changes were validated:
Manually tested with fake currency rates (HTTP responses modified on the fly via FiddlerCore)
Verified that it works no matter the selected field (From or To)
Verified that the currencies selected are kept after a refresh
2019-04-16 11:29:43 -07:00
Rudy Huyn
109326508f Improve the support of Narrator with parenthesis (#368)
* Modify how we manage Narrator with parenthesis and refactor right parenthesis

* Optimization

* remove extra spaces

* take feedback into account
2019-04-15 09:31:02 -07:00
Michał Janiszewski
afdda581a4 Drop unneeded const-qualifier on return type (#396) 2019-04-12 13:40:02 -07:00
Pepe Rivera
f6f10444f7 Simplify some of the calc engine string logic (#449)
Description of the changes:
Currently Calculator handles strings by defining integers for each type of function that can be performed, this integer will eventually correspond with an index in s_engineStrings which holds the corresponding display string for each function. Some functions such as Sin can have multiple strings (degrees, rads, grads, inverse). Functions like Sin are mapped to another array called "rgUfne" where a new integer is given depending on the output string which will then be given to s_engineStrings. The new integer returned by the "rgUfne" array runs the risk of overlapping with any new functions that may be added in CCommand.h. Furthermore, it is expected that the strings in s_engineStrings and rgUfne are defined in a particular order (not necessarily sequential), otherwise the logic will break. This makes adding new strings for new functions confusing and difficult, since a lot of the logic is not clearly defined.

This PR attempts to make this a bit simpler by changing the s_engineStrings and rgUfne arrays to be unordered_maps instead of arrays. For s_engineStrings the keys will now be strings, allowing the existing logic for indexing to be used by simply converting the number into a string to access the value. This will also allow us to create keys in the future that are not limited to integers but to strings that hold more meaning.

The rgUfne array will also be updated to be a map that will take in an integer and give you the corresponding string that can be passed to s_engineStrings. The UFNE object in the rgUfne array will also be updated to hold all the possible string keys for a function, instead of indexing them on other numbers that may overlap with existing definitions.

Now to add a new string for a new IDC_FOO function, we would just need to add the "FooString" resource keys to the g_sids array and use the updated rgUfne map to link the IDC_FOO value to the corresponding "FooString" resource key. This way the resource key can be a meaningful string, and not an integer that must be in any particular order.

How changes were validated:
Tested each function manually in standard, scientific, and programmer modes.
2019-04-11 15:20:01 -07:00
Daniel Belcher
7ac750f7e5
Fix invalid check of m_precedenceOpCount (#298)
The conditional m_precedenceOpCount >= 0 was always true because m_precendenceOpCount is an unsigned type. Update the conditional to simply be true and rely on a break statement in the loop. Although this member variable used to be a signed type, in practice, the value was never less than 0.

How changes were validated:
Manual. Unit tests pass locally.
2019-04-09 14:12:28 -07:00
Michał Janiszewski
f6a6aae6e6 Add additional defines for MSVC ARM and ARM64 to conv.cpp (#399)
Fixes ARM(64) regression introduced with #212
2019-03-28 11:17:06 -07:00
Michał Janiszewski
7a48f66807 Replace custom types with standard ones (#212)
Replace custom types with standard ones
2019-03-26 14:30:46 -07:00
Daniel Belcher
19e61e2b53 Disable use of min/max macros defined by Windows headers. (#363)
Description of the changes:
  Disable Windows-provided min/max macros using the NOMINMAX flag. Add the flag to each project's pch to disable the macros across the solution.

How changes were validated:
  Project builds.
  Unit tests pass.
  Smoke tests.

Fixes #362.
2019-03-25 11:28:29 -07:00
Michał Janiszewski
80a5fa01b0 Make CalculatorManager final rather than sealed (#331)
I have no idea if it is required to be `sealed`, I have seen no `^`
operator which makes me think it could be a regular C++ code, barring
the concurrency stuff.
2019-03-20 17:23:09 -07:00
Michał Janiszewski
597caf9c6b Fix order of initialization list in CalculatorManager, COpndCommand (#332)
This ensures the initialization order matches the layout of member
fields in class declaration
2019-03-20 16:45:30 -07:00
Michał Janiszewski
426a6c058d Remove expression with no effects from CalculatorManager (#337) 2019-03-20 16:43:51 -07:00
Shamkhal Maharramov
251ffffc50 Propose code-cleanups#2 (#253)
Description of the changes:

Remove redundancy
Simplify if statements
2019-03-20 14:28:30 -07:00
Michał Janiszewski
683b91aeec Remove redundant type qualifiers on function return type (#329) 2019-03-20 14:22:31 -07:00
Michał Janiszewski
94f0e8b320 Replace fallthrough comment with C++17's attribute (#334) 2019-03-20 14:19:30 -07:00
Michał Janiszewski
462694dcef Remove unused member field from CalculatorHistory (#330) 2019-03-20 10:58:32 -07:00
Michał Janiszewski
3d18dd38c2 Add explicit [[fallthrough]] attributes in Ratpack (#323) 2019-03-18 14:02:02 -07:00
Cyril
b8b0fdf86b Improving code style : verbosity, indentation levels (#200)
Fixing some nested if() statements and reducing indentation levels.

Making some sections less verbose, e.g:

if (a == 1)
{
    b = true;
}
else
{
    b = false;
}
↓

b = (a == 1)
2019-03-18 12:31:04 -07:00
Rudy Huyn
e40791d7ad Fix compilation issues due to unsigned/signed warnings treated as errors (#317) 2019-03-15 21:21:30 -07:00
Will
1113ff4b86 Updating comments per the C++ core guidelines and removing trailing whitespace (#194)
Fixed comments that were inconsistent with the style guidelines described in C++ core guidelines and the modern C++/WinRT language projections and removed trailing whitespace.

Inserted a space after the beginning of the comment so the text wasn't touching the // on all occurrences.

Removed all occurrences of trailing whitespace
2019-03-14 23:30:07 -07:00
Michał Janiszewski
a5e07418df Replace custom ARRAYSIZE macro with std::size (#208)
* Replace custom ARRAYSIZE macro with std::size
2019-03-14 21:06:12 -07:00
Stephanie Anderl
d37c75fec2
Fixes #282 Narrator does not convey error information when no more Right Parenthesis can be added in expression. (#284)
* Added narrator announcements when right parenthesis is clicked
2019-03-14 16:20:05 -07:00
Michał Janiszewski
be31288187 Fix declarations of functions (#186)
Move file-scope functions to anonymous namespaces.
Drop #pragma once from .cpp files
2019-03-13 13:15:08 -07:00
Jeff Genovy
251578047f Make 73 numeric constants const, moving them into .rdata (#234)
This change makes the 73 variables in ratconst.h actually
inline const, which allows them to move from the mutable .data
section of the executable, and into the read-only .rdata
section instead.

Moving data to the .rdata section has a number of benefits,
such as preventing possible corruption due to stray writes,
or other memory corruption.

Additionally, the initialization at run-time start-up is no
longer needed, so there is also a reduction in the .text
(code) section as well.

As a result the overall size of the Calculator.exe binary
(on x64 Release builds) decreases by 1,536 bytes (or ~1.5 KB)
with no change in behavior other than a small performance benefit.
2019-03-13 13:10:14 -07:00
Jeff Genovy
e6bd36ec2a Eliminate redundant copies of EMPTY_UNIT object, saving 2.5 KB. (#235)
### Description of the changes:

There are currently 11 copies of the `EMPTY_UNIT` object in the
`Calculator.exe` binary, which not only wastes space/footprint in the
binary itself, but also means that each copy must be separately
initialized, which effects performance.

The reason for this is that the object is defined in a shared header
file, which then is included by multiple .cpp files, causing each
translation unit (.obj) to get a full complete copy of the object.

By marking the object as `inline` we can
instruct the linker to define the object once, as we do
not need to have 11 unique versions of the EMPTY_UNIT object,
we only need 1.

The net result is that the `Calculator.exe` binary size is reduced by
2,560 bytes (or 2.5 KB) with no change in behavior, other than
the small performance benefit of not initializing 10 redundant copies
of the object.

### How changes were validated:
- Manually tested.
2019-03-12 19:24:37 -07:00
Shamkhal Maharramov
a98cb50a70 fix: redundant semicolons (#230)
### Description of the changes:
- Remove redundant semicolons in:
  - [x] UnitConverter.cpp
  - [x] DateCalculator.xaml.cpp
  - [x] CopyPasteManagerTest.cpp

### How changes were validated:
-  Manual
2019-03-09 08:16:05 -08:00
Petr Sedláček
248b762b80 Fix indentation and extra newline (#198) 2019-03-08 23:47:40 -08:00
Brett Waldbaum
64c6493312
Build with /W4 (#197)
All projects are built with warning level 4 (/W4) and treat warnings as errors (/WX).
Fixed build errors resulting from enabling these compiler flags.
2019-03-08 23:15:28 -08:00
Michał Janiszewski
0197bf18c1 Add override keyword where applicable (#188) 2019-03-08 11:18:01 -08:00
Michał Janiszewski
e2c7db644d Mark classes as final where applicable (#189) 2019-03-07 19:46:53 -08:00
Michał Janiszewski
0166daf5c7 Replace escape sequences with path separators in include paths 2019-03-07 15:51:00 -08:00
Josh Soref
84941c698e Spelling (#135) 2019-03-07 10:27:13 -08:00
Michał Janiszewski
2320697562 Catch polymorphic types by const-ref (#125) 2019-03-07 09:45:51 -08:00
Josh Soref
8a75dcd09d Switch urls from http: to https: (#137) 2019-03-07 08:56:25 -08:00
Jared Fuchs
8fa9a691cc Fix comment on IsEven
Looks like the comment on IsEven should read this way instead of "The assumption here is its numerator is 1 and we are testing the numerator is even or not"
2019-03-06 17:14:50 -08:00
Michał Janiszewski
6c0e4e81e7 Remove unused values 2019-03-06 16:47:02 -08:00
Michał Janiszewski
ca01a7e444 Add explicit [[fallthrough]] attribute 2019-03-06 16:44:28 -08:00
Edward Betts
0197fa41da Correct spelling mistakes 2019-03-06 16:10:14 -08:00
Michał Janiszewski
07ff1c372f Fix initialization order in CEngine (#118)
The order of initialization of fields is required to match the one in
class member fields declaration.
2019-03-06 14:51:21 -08:00
Daniel Belcher
057401f5f2 Suppress conversion warning in Ratpack/conv.cpp.
When building for x64, the compiler complains:
    warning C4267: 'argument': conversion from 'size_t' to 'ULONG', possible loss of data

In practice, the number string will not exceed a ULONG in length.
2019-03-05 21:42:24 -08:00
Matt Cooley
28f982a6e1
Apply spell check (#41) 2019-02-26 20:41:04 -08:00
Matt Cooley
654f09f544
Fix spelling in some comments (#38) 2019-02-25 15:41:16 -08:00
Josh Koon
ddc470949c
Rename scimath.h/cpp to RationalMath.h/cpp (#36) 2019-02-25 14:04:38 -08:00
Josh Koon
0cb5e9bae0
CalcEngine: Manage precision internally to Rational and convert functions to operator overrides (#35)
* Convert Rational::Negate to an operator override
* Convert Rational::Add to + and += operator overrides.
* Convert Rational::Sub to - and -= operator overrides.
* Convert Rational::Div and ::Mul to use /, /=, *, *= operator overrides.
* Convert Rational::Mod to use %= and % operator overrides
* Convert Rational::Rsh and ::Lsh to use >>=, >>, <<=, << operator overrides
* Convert Rational::And, ::Or, ::Xor to use &=, &, |=, |, ^=, ^ operator overrides
* Convert Rational relational functions to operator overrides
* Remove unnecessary precision arguments from Rational class and remove use of explicit Rational constructors in favor of implicit conversions for value types
* Remove unnecessary precision variable from RationalMath operations
* Replace unnecessary Rational::Not with Xor operation
* Remove unnecessary Rational::IsZero() in favor of == 0 comparisons
* Fix rounding issues in ratpak that result from using large precisions.
* Move assignment stmt out of IsCurrentTooBigForTrig
2019-02-25 11:41:32 -08:00
Josh Koon
73372283a0
CalcEngine: Remove the need to specify base/radix when working with Rational values (#31)
- Separates values from the representation (base/radix) of those values.
- Uses a single base for all values represented as Rationals.
- Rationals are converted to/from a specific base when they are converted to/from strings.
2019-02-22 10:00:19 -08:00
Josh Koon
5a530c4bed
Change m_nPrecNum from int to size_t and rename to m_precedenceOpCount (#33) 2019-02-21 16:36:54 -08:00
Josh Koon
32fb8500cb
Fix Log10 function (#27) 2019-02-21 10:50:32 -08:00
Josh Koon
2e18f6f477
Move RADIX_TYPE enum into its own header (#25)
This change moves the RADIX_TYPE enum into its own header. This resolves a compilation error and reduces the dependency graph by allowing RadixToStringConverter to include just the enum header rather than the entire CalcEngine header.

Change verified by ensuring Calculator build locally.
2019-02-20 11:07:32 -08:00
Josh Koon
995f077127
CalcEngine: Convert NumObj* functions to use Rationals and move under CalcEngine::RationalMath namespace (#12)
* Converts NumObj* functions to use Rationals. Places new functions under CalcEngine::RationalMath namespace
* Moves functions that correspond to an operator to the Rational class with intent to convert to operators in the future
* Consolidates use of RatPack's NUMBER and RAT data types to Number/Rational classes and RationalMath namespace.
2019-02-19 07:46:17 -08:00
Daniel Belcher
f210290ddc - Avoid referencing project headers from precompiled headers.
Before this change, the pchs for CalcViewModel and Calculator project referenced project headers.  If those project headers (or any of their dependencies) were to change, then the pch would be recompiled, slowing local build times.

  By removing references to project headers, the pch will be compiled once and is resilient to changes in the project.  Now that project headers are explicit about their dependencies, when there is a change to a project header only the translation units referencing the modified header will need to be rebuilt.

- Manually tested by ensuring Calculator project builds locally.

@Microsoft/calculator-team
2019-02-14 18:20:25 -08:00
Matt Cooley
ac63c1e1c2
Remove calcmanager ref (#9)
Calculator (the main app project) depends on CalcManager, but only transitively: Calculator -> CalcViewModel -> CalcManager.

However, Calculator's project file currently has a direct dependency on CalcManager. Let's remove this to make it harder to accidentally introduce new dependencies between the layers.

Also cleaning up some commented-out directives in the CalcManager MSBuild file.
2019-02-04 11:53:02 -08:00
Matt Cooley
177a606012
Clean up project structure in Visual Studio (#8)
A few small changes to improve the view of the code in Solution Explorer:
* Delete folders from solution explorer which don't appear on disk (Resource Files, PerfTrack)
* Delete files on disk which aren't compiled into the project (Type.xaml)
* Rename CalculatorHistory.Cpp to CalculatorHistory.cpp, for consistency with other files
2019-02-04 11:52:28 -08:00
Josh Koon
ebfce5a8cd Remove empty COpndCommand destructor. Cleanup constructor declaration. 2019-01-29 14:28:03 -08:00
Josh Koon
b70a12c6cf Add clarifying comment to call to CHistoryCollector::AddOpndToHistory 2019-01-29 14:27:24 -08:00
Josh Koon
db4a6eb9ea Return to initialization pattern in ExpressionCommand 2019-01-28 19:34:36 -08:00
Josh Koon
4883fab7f7 Convert ExpressionCommand and History collector to use Rational instead of PRAT 2019-01-28 19:14:15 -08:00
Howard Wolosky
c13b8a099e Hello GitHub 2019-01-28 16:24:37 -08:00