Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Comparison of C Sharp and Java
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Numeric applications=== To adequately support applications in the field of mathematical and financial computation, several language features exist.<ref name="computation">{{cite web |url=http://www.pds.ewi.tudelft.nl/pubs/papers/scicomp01.pdf |title=Java for Scientific Computation : Prospects and Problems |publisher=Pds.ewi.tudelft.nl |access-date=24 February 2015 |archive-url=https://web.archive.org/web/20070922004052/http://www.pds.ewi.tudelft.nl/pubs/papers/scicomp01.pdf |archive-date=22 September 2007 |url-status=dead |df=dmy-all}}</ref> Java's [[strictfp]] keyword enables strict floating-point calculations for a region of code. Strict floating-point calculations require that even if a platform offers higher precision during calculations, intermediate results must be converted to single/double. This ensures that strict floating-point calculations return exactly the same result on all platforms. Without strict floating-point, a platform implementation is free to use higher precision for intermediate results during calculation. C# allows an implementation for a given hardware architecture to always use a higher precision for intermediate results if available, i.e. C# does not allow the programmer to optionally force intermediate results to use the potential lower precision of single/double.<ref>{{cite web |title=C# Language Specification Version 5.0 |url=http://www.microsoft.com/en-us/download/details.aspx?id=7029 |quote=Floating-point operations may be performed with higher precision than the result type of the operation. For example, some hardware architectures support an "extended" or "long double" floating-point type with greater range and precision than the double type, and implicitly perform all floating-point operations using this higher precision type. Only at excessive cost in performance can such hardware architectures be made to perform floating-point operations with ''less'' precision, and rather than require an implementation to forfeit both performance and precision, C# allows a higher precision type to be used for all floating-point operations. Other than delivering more precise results, this rarely has any measurable effects. However, in expressions of the form x*y/z, where the multiplication produces a result that is outside the double range, but the subsequent division brings the temporary result back into the double range, the fact that the expression is evaluated in a higher range format may cause a finite result to be produced instead of an infinity. |publisher=Microsoft |access-date=28 October 2013 |at=4.1.6 Floating point types}}</ref> Although Java's floating-point arithmetic is largely based on IEEE 754 (Standard for Binary Floating-Point Arithmetic), certain features are unsupported even when using the strictfp modifier, such as Exception Flags and Directed Roundings, abilities mandated by IEEE Standard 754 (see [[Criticism of Java#Floating point arithmetic|Criticism of Java, Floating point arithmetic]]). C# provides a built-in decimal type,<ref>{{cite web |title=decimal vs. 110 |url=http://msdn.microsoft.com/en-us/library/system.decimalv=vs.110.aspx |access-date=24 February 2015}}{{dead link |date=June 2016|bot=medic}}{{cbignore|bot=medic}}</ref> which has higher precision (but less range) than the Java/C# double. The decimal type is a 128-bit data type suitable for financial and monetary calculations. The decimal type can represent values ranging from 1.0 Γ 10<sup>β28</sup> to approximately 7.9 Γ 10<sup>28</sup> with 28β29 significant digits.<ref>{{cite web |title=C# Language Specification Version 5.0 |url=http://www.microsoft.com/en-us/download/details.aspx?id=7029 |publisher=Microsoft | at=4.1.7 The decimal type}}</ref> The structure uses C# operator overloading so that decimals can be manipulated using operators such as {{mono|+}}, {{mono|-}}, {{mono|*}} and {{mono|/}}, like other primitive data types. The {{Javadoc:SE|java/math|BigDecimal}} and {{Javadoc:SE|java/math|BigInteger}} types provided with Java allow arbitrary-precision representation of decimal numbers and integer numbers, respectively. Java standard library does not have classes to deal with complex numbers. The {{csharp|BigInteger}},<ref name="microsoft1"/> and {{csharp|Complex}}<ref>{{cite web |title=Complex |url=http://msdn.microsoft.com/en-us/library/system.numerics.complexv=vs.110.aspx |access-date=24 February 2015}}{{dead link |date=June 2016|bot=medic}}{{cbignore|bot=medic}}</ref> types provided with C# allow representation and manipulation of arbitrary-precision integers and complex numbers, respectively. The structures use C# operator overloading so that instances can be manipulated using operators such as {{mono|+}}, {{mono|-}}, {{mono|*}}, and {{mono|/}}, like other primitive data types. C# standard library does not have classes to deal with arbitrary-precision floating point numbers (see [[Arbitrary-precision arithmetic#Arbitrary-precision software|software for arbitrary-precision arithmetic]]). C# can help mathematical applications with the {{csharp|checked}} and {{csharp|unchecked}} operators that allow the enabling or disabling of run-time checking for [[arithmetic overflow]] for a region of code.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)