Generalised floating point addition: Difference between revisions

Rewrote the task to be less prescriptive
m (→‎{{header|Ruby}}: copy/paste error)
(Rewrote the task to be less prescriptive)
Line 1:
{{Template:Draft task}}
IfIt is possible, defineto addition forimplement floating point numbersarithmetic wherein many different ways; though the digitsstandard areIEEE storedarithmetic implementation on modern hardware usually uses a fixed-width binary implementation (using a total of 32 bits for single-precision floats — <code>float</code> in ana arbitrarynumber base.of languages eg. theand digits64 bits for double-precision floats — <code>double</code>) many other schemes can be storedused. asFor binaryexample, the base need not be binary (alternatives include decimal, [[wp:Binary-coded decimal|binary-coded decimal]], orand even [[balanced ternary]]) and there is no requirement that a fixed number of digits be used.
 
Define addition for floating point numbers where the digits are stored in an arbitrary base; e.g. the digits can be stored as binary, decimal, [[wp:Binary-coded decimal|binary-coded decimal]], or even [[balanced ternary]].
ImplementYou should implement the code in a generalised form (such as a [[wp:Template (programming)|Template]], [[wp:Modular programming|Module]] or [[wp:Mixin|Mixin]] etc) that permits reusing of the code for different [[wp:Base_(exponentiation)#In_numeral_systems|Bases]].
 
If it is not possible to implement code inby providing an implementation that uses the ''syntax'' of the specific language then:
* noteNote the reason why this is.
* performDemonstrate that the language still supports the semantics of generalised floating point by implementing the ''test case'' using a built-in code or externala library.
 
'''Test case:'''
 
Use the Template to defineDefine [[wp:Arbitrary-precision arithmetic|Arbitraryarbitrary precision addition]] on floating point numbers stored(e.g., inencoding those numbers using Binary Coded Decimal, or using an arbitrary precision integer arithmetic library). Calculate the terms for -7 to 21 in this sequence of calculations:
{|class="wikitable" style="text-align: center; margin: 1em auto 1em auto;"
|+ Calculate the terms for -7 to 21 in this sequence of calculations
Line 26 ⟶ 27:
|etc.|| The final calculation will be over 256 digits wide || 1e72
|}
PerformYou will either need to implement multiplication, or perform the multiplication ofby 81 by using repeated additions. The results will always be 1e72.
 
;Bonus
Make the template (module, class, mixing, etc.) able to successfully handle using other bases to perform the above test case. Demonstrate using [[balanced ternary]].
 
Ideally the template should be able to successfully handle other bases - such as [[wp:Balanced ternary|Balanced ternary]] - to perform the above test case.
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - one minor extension to language used - PRAGMA READ, similar to C's #include directive.}}
Anonymous user