caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Arturo Borquez <aborquez@altavista.com>
To: wester@ilt.fhg.de
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Complex numbers in OCaml
Date: 27 Mar 2001 09:49:47 -0800	[thread overview]
Message-ID: <20010327174947.4199.cpmta@c012.sfo.cp.net> (raw)

On Tue, 27 March 2001, wester@ilt.fhg.de wrote:

> 
> Hi,
> 
> I need complex numbers. I tried it this way:
> 
> type number  = Real of float | Complex of (float*float);;
> 
> let add_num a b = 
>   match (a,b) with
>       (Real a, Real b)          -> Real (a +. b)
>     | (Real a, Complex (bx,by)) -> Complex (a +. bx, by) .................

Hi: Rolf:
Here is a little example of an alternative to operate with complex numbers. The key is to define a complex a a duple and define new opertators to do computations, ie +! for addition -! for substraction *! /!...

let (+!) (xr, xi) (yr, yi) = (xr +. yr), (xi +. yi);;
let a = (1.0, 2.0);;
let b = (0.0, -4.75);;
let z = a +! b;;
z;;
val z : float * float = 1, -2.75

The same applies for sub, mpy and div ops.
hope this helps.

Best regards.
Arturo Borquez


Find the best deals on the web at AltaVista Shopping!
http://www.shopping.altavista.com
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


             reply	other threads:[~2001-03-27 17:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-27 17:49 Arturo Borquez [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-09-21 22:25 [Caml-list] Complex numbers in ocaml Post Office!~/sentmail
2001-09-22 17:59 ` John Max Skaller
2001-03-27 16:22 [Caml-list] Complex numbers in OCaml wester
2001-03-27 17:19 ` Markus Mottl
2001-03-27 17:48   ` Jan Skibinski
2001-03-27 19:25     ` Markus Mottl
2001-03-28  1:04 ` Michael Hohn
2001-03-29 14:26 ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010327174947.4199.cpmta@c012.sfo.cp.net \
    --to=aborquez@altavista.com \
    --cc=caml-list@inria.fr \
    --cc=wester@ilt.fhg.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).