Code Monkey home page Code Monkey logo

flt's People

Contributors

jgoizueta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flt's Issues

Conversion to/from BigDecimal doesn't work within Spork

I have been picking at this issue on and off for weeks, but hadn't been able to make any progress on it until now. I have a bunch of RSpec specs that fail only when I'm using Spork, all with the same error message for the same line of code:

Flt::DecNum can't be coerced into BigDecimal

I followed the instructions in your README just now and added a file to ./config/initializers/flt.rb with these conversion functions in it:

DecNum.context.define_conversion_from(BigDecimal) do |x, context|
  DecNum(x.to_s)
end

DecNum.context.define_conversion_to(BigDecimal) do |x|
  BigDecimal.new(x.to_s)
end

I still get the error though. The mysterious thing to me is that even before I wrote that initializer, the specs all pass without Spork. It's not like I need to use Spork (obviously I've been okay without it for several weeks), but it is pretty annoying having such an arbitrary bug. Can you lend any insight into what's happening here, why it works outside of Spork, and what I can do to fix it?

Incorrectly rounded trigonometry results

After regenerating the trigonometry test data, one case is revealed where the result is not correctly rounded (trigonometry tests aspire to achieve same accuracy as HP classic 12-digit calculators).

  1) Failure:
TestTrig#test_cos [/Users/jgoizueta/dev/repos/flt/test/test_trig.rb:42]:
cos(10000000.6817)==-0.969490904178
input: [100000006817, -4] [10 rad 12].
Expected: DecNum('-0.969490904178')
  Actual: DecNum('-0.969490904177')

The problem goes away raising the internal extra precision to 4 digits:

diff --git a/lib/flt/trigonometry.rb b/lib/flt/trigonometry.rb
index 5ecea64..17afbd4 100644
--- a/lib/flt/trigonometry.rb
+++ b/lib/flt/trigonometry.rb
@@ -134,7 +134,7 @@ module Flt
       rev_sign = false
       s = nil
       num_class.context(self) do |local_context|
-        local_context.precision += 3 # extra digits for intermediate steps
+        local_context.precision += 4 # extra digits for intermediate steps
         x,k,pi_2 = local_context.reduce_angle2(x,2)
         rev_sign = true if k>1
         if k % 2 == 0
@@ -161,7 +161,7 @@ module Flt
       sign = x.sign
       s = nil
       num_class.context(self) do |local_context|
-        local_context.precision += 3 # extra digits for intermediate steps
+        local_context.precision += 4 # extra digits for intermediate steps
         x = x.copy_sign(+1) if sign<0
         x,k,pi_2 = local_context.reduce_angle2(x,2)
         sign = -sign if k>1

But It'd be nice to fix this by using better algorithms rather than increasing the brute force...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.